I have 2 areas Admin
and FrontEnd
(in that order).
When I am in a view in my FrontEnd area, ActionLink
always points to the Admin
area:
@Html.ActionLink("Checkout", "Address", "Checkout")
Will be http://localhost:53600/admin/Checkout/Address
but the Checkout controller is in my FrontEnd area.
I know I can solve this by specifying a routedata object in the action link and setting area = "FrontEnd"
but I don't want to. I want the ActionLink
helper to default to my current route.
Is this possible?
All the questions I've read on actionlink are people asking how to link to another area which indicates it defaults to the current area for them. Am I alone with this issue?
Edit, these are my routes which you can see are tied to the correct namespace:
Admin
public void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Administration_default",
"admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", area = "Administration", id = UrlParameter.Optional },
new[] { "CC.Web.Areas.Administration.Controllers" }
);
}
FrontEnd
public void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("Default",
"{controller}/{action}/{id}",
new {controller = "Home", action = "Index", area = "FrontEnd", id = UrlParameter.Optional},
new[] {"CC.Web.Areas.FrontEnd.Controllers"}
);
}
Areas should be registered in classes deriving from
AreaRegistration
overriding the methodvoid RegisterArea(AreaRegistrationContext context)
, see the msdn.The
AreaRegistrationContext
defines its own methods to register area routes that will add the required dataTokens for the areas that are used when generating links and urls:It also looks like the FrontEnd shouldn't be an area, so you could just have the standard MVC controllers and views (instead of the fronteand area) with an extra Admin area:
Remember that you should be calling
AreaRegistration.RegisterAllAreas();
at the beggining of your main RegisterRoutes method invoked on app start.