假设我有以下操作:
public ActionResult DoSomething()
{
// Some business logic
return RedirectToAction("AnotherAction", RouteData.Values);
}
public ActionResult AnotherAction(string name, int age)
{
...
}
以及以下形式:
<form method="post" action="DoSomething">
<input name="name" type="text" />
<input name="age" type="text" />
<input type="submit" value="Go" />
</form>
在该表单上点击提交将转到DoSomething动作,然后转到另一个动作- 将所有相关值传递给name和age。这是一种享受!
但我显然无法访问AnotherAction中的任何其他提交的表单值,因为从 DoSomething 重定向时它们会丢失:
public ActionResult AnotherAction(string name, int age)
{
// This won't work
var other = Request.Form["SomeDynamicVariable"];
}
更理想的是TransferToAction方法,它重新运行 MVC 引擎“想象”表单已发布到AnotherAction:
return TransferToAction("AnotherAction");
我可以这样做吗?
如果此功能开箱即用不可用,那么我将制作它,将其发布到博客并发布!