2011-03-05 158 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。