I have a layout page in ~/Views/Shared/_Layout.cshtml and it works great for all normal views that get rendered. However, I created an area called “Demos” and in the ~/Areas/Demos/Views/_ViewStart.cshtml file I pointed it to my original layout page.
This works just fine except some calls to @Html.ActionLink() are now being prefixed with the area name. So where @Html.ActionLink("Blog", "Index", "Blog") would normally generate a link like “website.com/Blog/Index” on area views it generates “website.com/Demos/Blog/Index”.
Any ideas?
To use areas open the Global.asax file and insert the following code into the Application_Start method
You can link within an area as you would in any MVC application but to generate a link to a different area, you must explicitly pass the target area name in the routeValues parameter for these methods.
nullparameter is required only because the ActionLink method overloads that have a routeValues parameter also have an htmlAttributes parameter but it is not required in order to be able to link between areas.UPDATE
You can use
RouteLink()instead ofActionLink(), to bypass the area registrations.The second parameter (“MyRoute”) is a route name registered in
Global.asaxso to useRouteLink()to link between different areas, you only need to specify the correct route name.