In Convention based routing, you need to define routes in the routing table. It helps you to keep URL clean and avoid database IDs in URL. For example, instead of ‘http://www.mindstick.com/forum/155738/what-is-validation-in-mvc’, we have ‘https://www.mindstick.com/forum/155739/define-viewbag-in-mvc’
It adds the advantage of being more ‘search robot’ friendly and which is good for SEO.
We just need to register this route table in Application_Start (Global.asax) using this code.
RouteConfig.RegisterRoutes(RouteTable.Routes);
How routing fits in an MVC application.
There are two type of routing in MVC
Convention based routing
Attribute-based routing(introduced in MVC 5)
Convention based routing:
Route templates are define in the webApiConfig level.
These routing templates works for the whole controller of the application.
Can we create our custom routes only?
In below figure, the default method that add routes to the route table which is located in the RouteConfig.cs file in the App_Start folder.
In the above image, we can see three things: “routes”, “IgnoreRoute” and “MapRoute”.
Routes : It is nothing but only a table which is a collection of routes defined in the routing table. When anyone hits some URL in the browser, an application first checks the existing route tables and match with routes.
IgnoreRoute: It is a collection of URL which should be ignored by the application.
MapRoute: It is used to add a new route to the routing table.
Attribute-based routing
Route templates are defined in the Controller Level or action level.
This routing template works only for those places where they define such as controller level or action level.
It is best suited for the rest full application
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
For example, instead of ‘http://www.mindstick.com/forum/155738/what-is-validation-in-mvc’, we have ‘https://www.mindstick.com/forum/155739/define-viewbag-in-mvc’
How routing fits in an MVC application.
There are two type of routing in MVC
Convention based routing:
In below figure, the default method that add routes to the route table which is located in the RouteConfig.cs file in the App_Start folder.
In the above image, we can see three things: “routes”, “IgnoreRoute” and “MapRoute”.
Routes : It is nothing but only a table which is a collection of routes defined in the routing table. When anyone hits some URL in the browser, an application first checks the existing route tables and match with routes.
Attribute-based routing