我想重定向到同一控制器中的另一个动作并传递一个参数值。我有这个代码:
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
in 中SomeAction
,它无济于事,因为它实际上TempData
是空的Index
。
我尝试的另一件事是RedirectToAction("Index","Test", new { param = isFailed})
在return
声明中使用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
.
是否有任何替代/解决方法可以做到这一点?简而言之,我想要这三件事:
- 重定向到
Index
行动。 param
将from的值传递SomeAction
到Index
。- 保留网址:
http://localhost/AreaName/Test/