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"));
   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

Categories: .NET | ASP.NET | Development | MVC
Actions: E-mail | Permalink | Comments (9) | Comment RSSRSS comment feed


June 2. 2008 19:42

Pingback from weblogs.asp.net

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


June 3. 2008 07:57

Hi Matt,

Would you be interested in including this in mvccontrib?


Jeremy Skinner

June 3. 2008 08:13

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


June 3. 2008 13: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 9. 2008 18:27

Perfect! Thanks.

Seth Websterer.com

June 20. 2008 14: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.


June 30. 2008 03:06

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

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

David J Hu

August 25. 2008 22:08

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

jorg visch

June 4. 2009 00:36



Comments are closed

Copyright © 2000 - 2024 , Excentrics World