具有共享布局的 ASP.NET MVC 区域
我在 ASP.NET MVC 3 应用程序中定义了一个区域(Admin),在该区域中创建了 _ViewStart.cshtml 并添加了 Layout = "~/Views/Shared/_Layout.cshtml"; 使其具有统一的站点布局。
我还在 _Layout.cshtml
中添加了以下代码:
if (HttpContext.Current.User.IsInRole("Admin"))
{
<li>@Html.ActionLink("Items List", "Index", "Items", new { area = "Admin" }, null)</li>
}
Admin
区域正确显示,并以 _Layout.cshtml
作为其布局。但页面中的所有导航链接现在都指向 Admin
子文件夹。
例如,在我的布局中,我有
,它指向 Mysite/主页/关于
。但点击管理链接后,“关于我们”链接指向/Admin/Home/About
。
我应该怎么做才能让 _Layout.cshtml 链接指向正确的地址?
谢谢。
I have defined an area (Admin) in my ASP.NET MVC 3 application, created _ViewStart.cshtml
in that area and addedLayout = "~/Views/Shared/_Layout.cshtml";
to it to have a unified site layout.
I also added the following code to _Layout.cshtml
:
if (HttpContext.Current.User.IsInRole("Admin"))
{
<li>@Html.ActionLink("Items List", "Index", "Items", new { area = "Admin" }, null)</li>
}
The Admin
area is displayed properly having _Layout.cshtml
as its layout. But all the navigation links in the page now point to Admin
subfolder.
For example in my layout I have <li>@Html.ActionLink("About Us", "About", "Home")</li>
, which points to Mysite/Home/About
. But after clicking the admin link, the "About Us" link points to /Admin/Home/About
.
What should I do to have _Layout.cshtml links pointing to the right address?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要从根控制器提供服务,只需为它们指定一个空白区域:
Simply specify a blank area for them if they are to be served from root controllers: