routing action within mvc4 area not able to map action

asp.net-mvc, asp.net-mvc-4, asp.net-mvc-routing, c#-4.0

Solution

I think you would just need a single route for this. Don't include the controller in the route, since it seems to be implied by starting with /ABC; just assign the controller as a default value:

context.MapRoute(
    "ABC_Home",
    "ABC/{action}/{id}",
    new { controller = "home", action="Index", id = UrlParameter.Optional },
    constraints: null,
    namespaces: new[] { "WebApplication.Areas.ABC.Controllers" }
}

Per your requirements, this will route /abc to /home/index, and will route /abc/details to /home/details.

Then, if you need to access other controllers you can add another rule for that, something like the default one:

context.MapRoute(
    "Default_Route",
    "{controller}/{action}/{id}",
    new { id = UrlParameter.Optional }
}

Problem

I am having trouble trying to get a route working in an area I have. My area is called ABC and I have a controller called Home within the area. I am able to hit the breakpoint with Home/Index if I browse "http://localhost:8000/abc" however when I try hit another action called details like "http://localhost:8000/ABC/details" I get a 404. I have tried ``` context.MapRoute( "details", "ABC/Home/{action}/{id}", new { action = "details", id = UrlParameter.Optional }, constraints: null, namespaces: new[] { "WebApplication.Areas.ABC.Controllers" } ); context.MapRoute( "ABC_Home", "ABC/{controller}/{action}/{id}", new { controller = "home",action="Index", id = UrlParameter.Optional }, constraints: null, namespaces: new[] { "WebApplication.Areas.ABC.Controllers" } ); ``` This allows me to hit the action if I use "http://localhost:8000/ABC/Home/Details" ``` context.MapRoute( "details", "Home/Home/{action}/{id}", new {controller="home", action = "details", id = UrlParameter.Optional }, constraints: null, namespaces: new[] { "WebApplication.Areas.ABC.Controllers" } ); ``` Ideally I don't want to use home within the url if possible. What am I doing wrong? Any help would be awesome!

Original source