Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
864 views
in Technique[技术] by (71.8m points)

ASP.NET MVC Areas with shared layout

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.

question from:https://stackoverflow.com/questions/7828525/asp-net-mvc-areas-with-shared-layout

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...