asp.net-mvc-5Attribute routing in mvc-5


Syntax

  1. {productId:int}/{productTitle} Mapped to ProductsController.Show(int id)

  2. {username} Mapped to ProfilesController.Show(string username)

  3. {username}/catalogs/{catalogId:int}/{catalogTitle} Mapped to CatalogsController.Show(string username, int catalogId)

Remarks

Routing is how ASP.NET MVC matches a URI to an action. MVC 5 supports a new type of routing, called attribute routing. As the name implies, attribute routing uses attributes to define routes. Attribute routing gives you more control over the URIs in your web application.

The earlier style of routing, called convention-based routing, is still fully supported. In fact, you can combine both techniques in the same project.