One of the limitations of using RedirectToAction("actionName", {object with properties}) is that RedirectToAction () does not have an overload that accepts RedirectToAction(ActionResult(), {object with properties}) , so you have to use magic strings for the name actions (and possibly the name of the controller).
If you use the T4MVC library, it includes two freely used API methods ( AddRouteValue(...) and AddRouteValues(...) ), which allow you to easily add a single querystring parameter, all object properties or the entire Request.QueryString. You can call these methods either on your own ActionResult T4MVC objects, or directly on the RedirectToAction () method. Of course, T4MVC is getting rid of magic strings!
As an example: suppose you want to redirect to the login page for an unauthenticated request and pass the originally requested URL as a parameter to the query string so that you can go there after a successful login. Any of the following syntax examples will work:
return RedirectToAction(MVC.Account.LogOn()).AddRouteValue(@"returnUrl", HttpUtility.UrlEncode(Request.RawUrl));
or
return RedirectToAction(MVC.Account.LogOn().AddRouteValue(@"returnUrl", HttpUtility.UrlEncode(Request.RawUrl)));
Martin_ATS Jan 10 '13 at 20:10 2013-01-10 20:10
source share