How to override Default Route ? | ASP.Net MVC Interview Question

, ,
  • Use specific [Route] on a specific Action.
  • It'll override the default settings on the Controller.

       BookingController.cs

    [RoutePrefix("Booking")]
    [Route("{action=index}")]
    public class BookingController : Controller
    {
        // eg: /Booking
        public ActionResult Index() { return View(); }

        // eg: /Booking/Edit/3
        [Route("Edit/{bookId:int}")]
        public ActionResult Edit(int bookId) { return View(); }

    }

Above overridden Route on Browser is as below