Suppose I have the following actions:
public ActionResult DoSomething()
{
// Some business logic
return RedirectToAction("AnotherAction", RouteData.Values);
}
public ActionResult AnotherAction(string name, int age)
{
...
}
And the following form:
<form method="post" action="DoSomething">
<input name="name" type="text" />
<input name="age" type="text" />
<input type="submit" value="Go" />
</form>
Hitting submit on that form will go to the DoSomething action, and in turn to AnotherAction - passing in all the relevant values into name and age. It works a treat!
But I obviously cannot access any other submitted form values in AnotherAction, because they are lost when redirecting from DoSomething:
public ActionResult AnotherAction(string name, int age)
{
// This won't work
var other = Request.Form["SomeDynamicVariable"];
}
What would be more ideal is a TransferToAction method, that re-runs the MVC engine "imagining" the form had been posted to AnotherAction instead:
return TransferToAction("AnotherAction");
Can I do this?
If this functionality is not available out-of-the-box, then I'll make it, blog it and post it!