与共享的布局ASP.NET MVC区 [英] ASP.NET MVC Areas with shared layout
问题描述
我在ASP.NET MVC 3应用程序,创建 _ViewStart.cshtml
在这一领域已经定义了一个区域(管理员),并添加布局= 〜/查看/共享/ _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.
我还增加了以下code到 _Layout.cshtml
:
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>
}
显示管理
区正常有 _Layout.cshtml
作为其布局。但是,在该页面中的所有导航链接现在指向管理
子文件夹。
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.
例如在我的布局我有&LT;李&GT; @ Html.ActionLink(关于我们,关于,家庭)&LT; /李&GT;
,它指向 MYSITE /首页/关于
。但点击管理链接后,关于我们链接指向 /管理/首页/关于
。
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
.
我应该怎么做有指向正确的地址_Layout.cshtml链接?结果
谢谢你。
What should I do to have _Layout.cshtml links pointing to the right address?
Thanks.
推荐答案
只需指定他们的一个空白区域,如果他们是被从根控制器供应:
Simply specify a blank area for them if they are to be served from root controllers:
<li>@Html.ActionLink("About Us", "About", "Home", new { area = "" }, null)</li>
这篇关于与共享的布局ASP.NET MVC区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!