Fio*_*onn 8 asp.net asp.net-mvc asp.net-mvc-areas razor
有没有办法在区域之间分享部分剃刀视图?
例如登录部分,我发现如果我使用@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
Run Code Online (Sandbox Code Playgroud)
部分视图来源:
@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") ]
}
Run Code Online (Sandbox Code Playgroud)
谢谢
您可以在ActionLink()方法中指定区域(或缺少一个):
Html.ActionLink(@Messages.Logout, "Logout", "Account", new { Area = "" }, new{})
Run Code Online (Sandbox Code Playgroud)
这将确保链接无法解析为当前区域内的URL.
| 归档时间: |
|
| 查看次数: |
2825 次 |
| 最近记录: |