eWorld.UI - Matt Hawley

Ramblings of Matt

Lambda Based RedirectToAction Sample Updated to MVC Preview 3

May 29, 2008 18:44 by matthaw

I took my Lambda based RedirectToAction solution I previously blogged about and updated it to work against the Preview 3 bits. I also took the liberty to fix the bug where you couldn't actually call another controller's action. Some notable changes in the source, is that ActionRedirectResult is no more - as it's replaced with RedirectToRouteResult. I think this was a good consolidation between RedirectToAction and RedirectToRoute since they basically do exactly the same thing. You'll also notice that there are 3 more extension methods, which was necessary to fix the prior bug. Now, you can write code like

   1:  // for actions off of the current controller
   2:  return this.RedirectToAction(c => c.Login());
   3:  return this.RedirectToAction(c => c.Login("matt"));
   4:   
   5:  // alternatively, within the UserController you can do the following
   6:  return this.RedirectToAction<ProductController>(c => c.View(102));

I'm not going to post the entire code sample as you can download it here. Enjoy it, and let me know of anything else you'd like to see.

kick it on DotNetKicks.com


Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

May 30. 2008 08:42

Pingback from weblogs.asp.net

Lambda Based RedirectToAction Sample Updated to MVC Preview 3 - eWorld.UI - Matt Hawley

weblogs.asp.net

May 30. 2008 20:57

Hi Matt,

Would you be interested in including this in mvccontrib?

Jeremy

Jeremy Skinner

May 30. 2008 21:13

@Jeremy - yeah, I'll get it in there probably late next week

matthaw

May 31. 2008 02:31

Not only did this fix my problem calling another controller's action, but it fixed my problem where my session variable was being destroyed. Much obliged!

Mike B

June 6. 2008 07:27

Perfect! Thanks.

Seth Websterer.com

June 17. 2008 03:02

Nice job, this is great. I removed the (this) extension bits and just added it to my base controller class overloading RedirectToAction since it doesn't have any conflicting <T> methods and the signatures are unique. Works like a charm, and is much cleaner. I hope they add this into the core MVC eventually.

Shannon

June 26. 2008 16:06

Building off of this example, I suppose we can also do this...

<%= Html.ActionLink<ProductController>(c => c.View(102)) %>

David J Hu

August 22. 2008 11:08

I almost started to build it myself, good job. Hopefully it will be added to the MVC core.

jorg visch

May 29. 2009 20:21

<%= Html.ActionLink<ProductController>(c => c.View(102)) %>

that's right thanks david.

Lap Band

May 31. 2009 13:36

Cool

yazılım

June 10. 2009 01:46

Thanks for update ya.

furnace filter

June 10. 2009 17:07

I almost started to build it myself, good job. Hopefully it will be added to the MVC core.

dog forums

June 22. 2009 04:51

Works like a charm, and is much cleaner. I hope they add this into the core MVC eventually.

affordable online education

June 22. 2009 04:54

good job. Hopefully it will be added to the MVC core.

online colleges degree

July 3. 2009 05:11

thanks for the preview looks nice

Define

July 3. 2009 05:13

thanks a lotf or sharing this with us

Weight loss pills

Add comment


 

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

July 3. 2009 21:38



Copyright © 2000 - 2009 , Excentrics World