ASP.NET MVC Areas with shared layout

感情迁移 提交于 2019-12-03 04:43:40

问题


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.


回答1:


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>


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!