Explain attribute based routing in MVC?

Posted by  Lee Patric
 313  View(s)
Ratings:
Rate this:
  1. Explain attribute based routing in MVC?

    Its feature is introduced in MVC 5. In pursuance of that the "Route" attribute, we can define the URL structure. For instance, in the below code we have decorated the "GotoAbout" action with the route attribute. According to the route attribute that the "GotoAbout" can be invoked using the URL structure "Users/about".

    public class HomeController : Controller
    
    {
           [Route("Users/about")]
           public ActionResult GotoAbout()
           {
               return View();
           }
    }

Answer