Routing is the way to locate the action that matches the URI in ASP.NET MVC. Sometimes it is required to have a route that is different in pattern from other routers in the application and is not possible to configure it by making use of convention-routing. In MVC 5, a new type of routing is introduced, called attribute routing. Attribute Routing has given more flexibility to configure routes that are specific to any controller/action. Like the name says, routes are added as an attribute to controller/action. This type of routing provides you more control over the URIs in your web application. Example of Attribute Routing: [Route(“{category:int}/{categoryName}”)]
public ActionResult Show(int categoryId) { … } To enable attribute routing, call MapMvcAttributeRoutes during configuration. Route Prefixes: Route Prefixes are the prefix for any route that we want to apply, this is done by defining the route prefix on a controller so that all the action methods inside it can follow the prefix. [RoutePrefix("category")]
public class CategoryController : Controller
{ .... }