Explain attribute based routing in MVC?

Category: C SharpExplain attribute based routing in MVC?
Editor">Editor Staff asked 2 years ago

Explain attribute based routing in MVC?

1 Answers
Editor">Editor Staff answered 2 years ago

In ASP.NET MVC 5.0 we have a new attribute route,cBy using the “Route” attribute we can define the URL structure. For example in the below code we have decorated the “GotoAbout” action with the route attribute. The route attribute says that the “GotoAbout” can be invoked using the URL structure “Users/about”.
 
Hide Copy Code

 

  1. public class HomeController: Controller  
  2. {  
  3.     [Route(“Users/about”)]  
  4.     publicActionResultGotoAbout()  
  5.     {  
  6.         return View();  
  7.     }  
  8. }