ASP.net MVC - 在区域之间共享部分
有没有办法在区域之间共享部分剃刀视图?
例如登录部分,如果我使用 @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") ]
}
谢谢
is there some way to share a partial razor view between areas?
For example a login partial, it is found if i use @Html.Partial("_LoginPartial")
but the URLs Html.ActionLink
generates are local to the calling area (even though the partial itself is not part of the area).
_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
Partial view source:
@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") ]
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
ActionLink()
方法中指定区域(或缺少区域):这将确保链接不会解析为当前区域内的 URL。
You can specify the area (or lack of one) in the
ActionLink()
method:This will ensure the link does not resolve to a URL within the current area.