Reputation: 229
I have defined MVC controller in my MVC web application. I have 5 different action names defined in the controller. All actions are doing different things.
What i want to do is defined a common MVC route in global.asax instead of 5 different MVC routes. One route i have defined like this in global.asax file.
routes.MapRoute(
"Action1/1", // Route name
"xyz/check-data1", // URL with parameters
new { controller = "CheckDate", action = "Check1" } // Parameter defaults
);
I need 5 different routes here because these 5 different routes will be called 5 hyperlinks in my web page.
I do not want to do copy and paste above route and create 5 different routes. For e.g. one more route i can defined like this as below.
routes.MapRoute(
"Action2/2", // Route name
"xyz/check-data2", // URL with parameters
new { controller = "CheckDate", action = "Check2" } // Parameter defaults
);
Please suggest me on this.
Upvotes: 0
Views: 63
Reputation: 239220
The typical pattern is to standardize your actions so that they can work with the default route:
/{Controller}/{Action}/{id?}
If you're not going to use standard actions, then you have no choice but to specify your routes individually and manually.
However, there's a nuget package called AttributeRouting that lets you specify the routes on the actions, themselves, using an attribute. This is often easier and more fluid if you're going to be dealing with a lot of custom routes.
Upvotes: 2