Home > DeveloperSection > Interviews > What is the advantage of defining route structures in the code?

Posted on    February-07-2016 10:27 PM

 ASP.Net C#  ASP.Net  ASP.NET MVC 
Ratings:
 1 Answer(s)
  305  View(s)
Rate this:

Anupam Mishra

Total Post:23

Points:115
Posted on    February-07-2016 11:27 PM

Most of the time developers code in the action methods. Developers can see the URL structure right upfront rather than going to the “routeconfig.cs” and see the lengthy codes. For instance in the below code the developer can see right upfront that the “GotoForm” action can be invoked by four different URL structure.

This is much user friendly as compared to scrolling through the “routeconfig.cs” file and going through the length line of code to figure out which URL structure is mapped to which action.

public class HomeController : Controller
{
       [Route("Home/About")]
       [Route("Home/Account Details")]
       [Route("Home/Our Team")]
       [Route("Home/About Company")]
       public ActionResult GotoForm()
       {
           return View();
       }
}

Don't want to miss updates? Please click the below button!

Follow MindStick