我如何重定向到ASP.NET MVC的previous行动? [英] How do I redirect to the previous action in ASP.NET MVC?

查看:108
本文介绍了我如何重定向到ASP.NET MVC的previous行动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我有一些网页

Lets suppose that I have some pages


  • some.web /用品/细节/ 5

  • some.web /用户/信息/鲍勃

  • some.web /富/酒吧/ 7

  • some.web/articles/details/5
  • some.web/users/info/bob
  • some.web/foo/bar/7

这可以拨打的共同效用控制器像

that can call a common utility controller like

区域设置/变更/ ES 授权/登录

我如何得到这些方法(更改登录)重定向到previous行动( 详细信息信息),而通过previous参数,它们( 5 鲍勃 7 )?

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?

推荐答案

尝试:

public ActionResult MyNextAction()
{
    return Redirect(Request.Referrer);
}

另外,触摸什么达林说,试试这个:

alternatively, touching on what darin said, try this:

public ActionResult MyFirstAction()
{
    return RedirectToAction("MyNextAction",
        new { r = Request.Url.ToString() });
}

然后

public ActionResult MyNextAction()
{
    return Redirect(Request.QueryString["r"]);
}

这篇关于我如何重定向到ASP.NET MVC的previous行动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆