【问题标题】:Redirect from one Area's action to a action in the "root"-area?从一个区域的动作重定向到“根”区域中的动作?
【发布时间】:2011-01-04 18:52:09
【问题描述】:

我使用的是最新版本的 ASP.Net MVC 2 RC。

我的问题是,如何从“博客”区域中的一个操作重定向到应用程序“根”(无区域)中存在的主控制器中的索引操作?

我试过了:

return RedirectToAction("index", "home");

但这会重定向到 /Blog/home,其中 Blog 是我所在区域的名称。

【问题讨论】:

    标签: asp.net asp.net-mvc routing asp.net-mvc-routing


    【解决方案1】:

    试试这个:

    return RedirectToAction("index", "home", new { area = "" });
    

    【讨论】:

    • 谢谢,它成功了。但是,ViewData 似乎丢失了:S 我将使用 Sessions 代替 :)
    【解决方案2】:

    如果使用默认路由,这也应该可以,但不确定 ViewData 会发生什么。

    return Redirect("~/");
    

    【讨论】:

    • 这对我不起作用,但我没有投反对票,因为它可能对其他人有用。
    猜你喜欢
    • 2020-08-03
    • 1970-01-01
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多