次のアクションがあるとします。
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アクションに移動し、 AnotherActionに移動して、関連するすべての値をnameとageに渡します。それは御馳走になります!
しかし、 DoSomething からリダイレクトすると失われるため、 AnotherActionで送信された他のフォーム値にアクセスすることはできません。
public ActionResult AnotherAction(string name, int age)
{
// This won't work
var other = Request.Form["SomeDynamicVariable"];
}
より理想的なのはTransferToActionメソッドで、代わりにフォームがAnotherActionに投稿されたことを「想像」して MVC エンジンを再実行します。
return TransferToAction("AnotherAction");
これはできますか?
この機能がすぐに利用できない場合は、作成してブログに投稿し、投稿します。