如何重定向到 ASP.NET MVC 中的上一个操作? [英] How do I redirect to the previous action in ASP.NET MVC?
本文介绍了如何重定向到 ASP.NET MVC 中的上一个操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一些页面
some.web/articles/details/5
some.web/users/info/bob
some.web/foo/bar/7
可以调用像
这样的通用实用程序控制器locale/change/es
或 authorization/login
如何让这些方法(change
、login
)重定向到之前的操作(details
、info
, bar
) 同时将前面的参数传递给它们 (5
, bob
, 7
)?>
简而言之:如何在另一个控制器中执行操作后重定向到我刚刚访问的页面?
解决方案
尝试:
public ActionResult MyNextAction(){返回重定向(Request.UrlReferrer.ToString());}
或者,触及达林所说的,试试这个:
public ActionResult MyFirstAction(){return RedirectToAction("MyNextAction",新 { r = Request.Url.ToString() });}
然后:
public ActionResult MyNextAction(){返回重定向(Request.QueryString["r"]);}
Lets suppose that I have some pages
some.web/articles/details/5
some.web/users/info/bob
some.web/foo/bar/7
that can call a common utility controller like
locale/change/es
or authorization/login
How do I get these methods (change
, login
) to redirect to the previous actions (details
, info
, bar
) while passing the previous parameters to them (5
, bob
, 7
)?
In short: How do I redirect to the page that I just visited after performing an action in another controller?
解决方案
try:
public ActionResult MyNextAction()
{
return Redirect(Request.UrlReferrer.ToString());
}
alternatively, touching on what darin said, try this:
public ActionResult MyFirstAction()
{
return RedirectToAction("MyNextAction",
new { r = Request.Url.ToString() });
}
then:
public ActionResult MyNextAction()
{
return Redirect(Request.QueryString["r"]);
}
这篇关于如何重定向到 ASP.NET MVC 中的上一个操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文