I'm attempting to specify a route in MVC4 that ignores a controller name if presented with a specific action name. For example.
mysite.com/AnyControllerNameHere/SpecificAction - Would let me specify the controller and action to use while
mysite.com/AnyControllerNameHere/NotSpecificAction - Would take me the the AnyControllerNameHere Controller and NotSpecificAction method like the MVC default.
I've attempted to code something up but it doesn't seem to do what I want. Full route config is just the MVC defaults plus me attempting to do this so...
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"SpecificAction",
"{controller}/SpecificAction",
new { controller = "Home", action = "SpecificAction" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
"SpecificAction"is before the default route declaration it should work. So please your full route config!