2011-03-05 165 views
8

是否有某种方式可以在区域之间共享部分剃须区域视图?ASP.net MVC - 在区域之间共享部分区域

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

_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") ] 
} 

感谢

回答

9

您可以在ActionLink()方法指定区域(或没有一个):

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

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