同じコントローラーの別のアクションにリダイレクトし、1 つのパラメーター値を渡したいです。私はこのコードを持っています:
public ActionResult Index()
{
}
public ActionResult SomeAction()
{
if (isFailed)
{
// Redirect to Index Action with isFailed parameter so that some message gets displayed on Index page.
}
}
使用について読みましTempData
たが、私のセッションは(何らかの目的で)読み取り専用であるため、にデータを保存するTempData
と、実際には空であるSomeAction
ため役に立ちません。TempData
Index
私が試したもう1つのことは、RedirectToAction("Index","Test", new { param = isFailed})
in return
statement of SomeAction
. これは機能し、 を使用してparam
実際にアクセスできますが、これに関する問題は、URL が必要な場所になることです。Index
Request.QueryString['param']
/AreaName?param=true
/AreaName/Test/
これは私のルートマップです:
context.MapRoute(
"default",
"AreaName/{controller}/{action}/{param}",
new { controller="Test", action = "Index", param=UrlParameter.Optional },
);
MyJS.js から「post」を使用してフォームを送信していSomeAction
ます。
これを行うための代替/回避策はありますか? ざっくり言うと、以下の3つが欲しいです。
- アクションにリダイレクトし
Index
ます。 param
fromの値をSomeAction
に渡しますIndex
。- URL を保持します。
http://localhost/AreaName/Test/