How to Assign Names to Routes? | ASP.Net MVC Interview Question

, ,
  • Specify a Name for a Route
  • By using that Name, you can easily allow URI generation for it
  • Well,It's like this : [Route("Booking", Name = "Payments")]

  BookingController.cs

 public class BookingController : Controller
    {
        // eg: /Booking
        [Route("Booking", Name = "Payments")]
        public ActionResult Payments() { return View(); }
    }

  • After that you can generate a Link is using Url.RouteUrl
  • It's like this : 
    <a href="@Url.RouteUrl("Payments")">Payments Screen</a>

Note : On the above code, "Payments" is a Route Name