【问题标题】:ASP.net MVC - Sharing partials between areasASP.net MVC - 在区域之间共享部分
【发布时间】:2011-03-05 00:05:38
【问题描述】:

有什么方法可以在区域之间共享局部视图吗?

例如登录部分,如果我使用@Html.Partial("_LoginPartial"),但 Html.ActionLink 生成的 URL 是调用区域的本地部分(即使部分本身不是该区域的一部分)。

_LoginPartial.cshtml is in /Views/Shared/_LoginPartial.cshtml
Calling view is inside /Areas/Somearea/Views

Links generated are like: http://example.com/Somearea/Account/Login
But should always be: http://example.com/Account/Login

部分视图来源:

@if(Request.IsAuthenticated) {
    <text>Welcome <b>@Context.User.Identity.Name</b>!
    [ @Html.ActionLink(@Messages.Logout, "Logout", "Account") ]</text>
}
else {
    @:[ @Html.ActionLink(@Messages.Login, "Login", "Account") ]
}

谢谢

【问题讨论】:

    标签: asp.net asp.net-mvc razor asp.net-mvc-areas


    【解决方案1】:

    您可以在ActionLink()方法中指定区域(或缺少区域):

    Html.ActionLink(@Messages.Logout, "Logout", "Account", new { Area = "" }, new{})
    

    这将确保链接不会解析为当前区域内的 URL。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 2019-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多