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 Answer 1

49

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>
Sign up to request clarification or add additional context in comments.

1 Comment

For @Html.Action(), it throws compilation error when specifying it as blank area as follows '@Html.Action("About", "Home", new { area = "" })' Need help to resolve this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.