I am trying to play with with is possible with routes in my ASP.NET MVC3 application and try reduce some of my mapping code. I am using trying to us a common UserController/View accross my application across a number of different entities. For example, you have Stores and Companies, and each has their own set of users. Is there any way to reduce the following two routes:
routes.MapRoute(
"StoreUsers", // Route name
"Store/Details/{entityID}/User/Index", // URL with parameters
new { controller = "User", action = "StoreIndex"} // Parameter defaults
);
routes.MapRoute(
"CompanyUsers", // Route name
"Company/Details/{entityID}/User/Index", // URL with parameters
new { controller = "User", action = "CompanyIndex"} // Parameter defaults
);
To something which resembles this?
routes.MapRoute(
"EntityUsers", // Route name
"{entity}/Details/{entityID}/User/Index", // URL with parameters
new { controller = "User", action = entity + "Index"} // Parameter defaults
new { entity = "(Store|Company)" } //Parameter constraints
);
and have the {action} parameter (and {action} default) set to: {entity} + "Index" so it can be used for entity entity which matches the constraints.
I am only reducing 2 routes to 1 here, but my real issue involves more then just these two entities, and if I can get this to work, I can use this for other controllers that have to mimic the same functionality and other actions as well (Create, Edit, etc).
Thanks