0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.