Reputation: 33071
Is it possible to define a route in MVC that dynamically resolves the action based on part of the route?
For example:
`/products/create/widget`
Would resolve to ProductsController.CreateWidget(Widget);
I want the route to be dynamic:
routes.MapRoute(
"Create",
"/products/create/{productType}",
new { controller = "Products", action = "Create{productType}" }
);
I need to have multiple Create actions that take in different model types but I don't want to add a new route every time I add one. Without appending the name to the action I get an ambiguous method error. Is it possible to do this?
Upvotes: 1
Views: 833
Reputation: 5644
I think you probably need to create your own custom route object derived from the RouteBase where you can assign action based on particular part of the Url. Take a look at this example.
Upvotes: 1