MVC行动历史

时间:2011-06-06 13:41:49

标签: model-view-controller action

我有两个列出项目的动作。 Index()列出所有项目,Filtered(string foo)根据foo过滤项目列表。当用户创建一个新项目时,我希望能够根据它们之前的位置将它们重定向回Index()或Filtered(string foo)。

我怎样才能做到这一点,或者重复我的行动以使其发挥作用?

1 个答案:

答案 0 :(得分:0)

您可以修改ActionResult以接受包含用户来源的URL路径的字符串。

这样的事情:

[HttpPost]
    public ActionResult CreateFoo(Blah model, string returnUrl)
    {
        // Do something here
        if (!String.IsNullOrEmpty(returnUrl)) // As long as a return URL was passed
        {
            return Redirect(returnUrl); // Return them to this URL
        }
        else
        {
            return RedirectToAction("Index", "Home"); // Otherwise Go Home
        }
   }

我没有很多ASP.NET MVC的经验,因此可以有更好的内置方法来处理这个问题。谷歌搜索'asp.net mvc重定向到请求者'可能会产生更有用的东西,这实际上是你想要的是重定向回请求路由。