On my home controller all but one action has no ID parameter, for all of the actions without an ID parameter I would like the action but not the controller to show in the URL. For one action I would like neither the controller or action to show in the URL, only the ID parameter for that action, e.g.:
routes.MapRoute(
"OnlyCourse",
"{courseabbrev}",
defaults: new { controller = "Home", action = "course", courseabbrev = UrlParameter.Optional }
);
routes.MapRoute(
"OnlyAction",
"{action}",
defaults: new { controller = "Home", action = "Index"}
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{courseabbrev}",
defaults: new { controller = "Home", action = "Index", courseabbrev = UrlParameter.Optional }
);
However if I put the OnlyCourse route first the index action routes through it and if I put the OnlyAction route first the OnlyCourse route is not found. How can I get these routes to respond to specific actions independently?
edit -
So for example the URL for Only Course (course action) would be:
http://www.sitename.come/courseabbrev
and the URL for the other actions would be
http://www.sitename.com/action
I've tried the following now:
routes.MapRoute(
"OnlyCourse",
"{courseabbrev}",
defaults: new { controller = "Home", action = "course"},
constraints: new { action = "course" }
);
routes.MapRoute(
"OnlyAction",
"{action}",
defaults: new { controller = "Home" }
);
And this does the trick for the index action, however any other action still uses the OnlyCourse route. I tried adding a constraint but it doesn't seem to do much as that route will consider all actions aside from Index it seems.