Explain attribute based routing in MVC?

Lee Patric

Total Post:4

Points:20

Posted by  Lee Patric
 102  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