Tutorial :How do I return a method paramenter with RedirectToAction



Question:

I have two method signatures at the moment.

public ActionResult Edit(bool? failed)    [AcceptVerbs(HttpVerbs.Post)]  public ActionResult Update(FormCollection collection)  

In the Update method when the password update fails I want to return to the Edit action with failed == true. However using the line

return RedirectToAction("Edit", true);  

doesn't seem to achieve this. (I do end up at the Edit Action but the bool value is null.) How else can I redirect to an action and still have the bool value hold?

Thanks


Solution:1

You are close - try this:

return RedirectToAction("Edit", new { failed = true });  


Solution:2

I'm afraid RedirectToAction isn't as simple as that... you need to pass the parameter as a route value dictionary. Try:

return RedirectToAction("Edit", new { failed = true });   

See http://msdn.microsoft.com/en-us/library/system.web.mvc.controller.redirecttoaction.aspx


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »