Attribute based routing in MVC 5 we can define the route in the same place where action method is defined Here we specified the route for the controller GetElectronicItems [Route( "Products/Electronics/{id}" )] public ActionResult GetElectronicItems( string id) { ViewBag.Id = id; return View(); } To enable attribute based routing in RouteConfig.cs we need to add the following in the RouteConfig file. public static void RegisterRoutes(RouteCollection routes) { routes.MapMvcAttributeRoutes(); } Optional Parameter We can also specify if there is any optional parameter in the URL pattern defined by t...
A Blog For Passionate Dot net Developers