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

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

Comments

May 30. 2008 02: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 14:57

Hi Matt,

Would you be interested in including this in mvccontrib?

Jeremy

Jeremy Skinner

May 30. 2008 15:13

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

matthaw

May 30. 2008 20: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 01:27

Perfect! Thanks.

Seth Websterer.com

June 16. 2008 21: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 10: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 05:08

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

jorg visch

Add comment


 

  Country flag

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



Live preview

October 7. 2008 09:18



Copyright © 2000 - 2008 , Excentrics World