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

, ,


  • You can apply the [Route] attribute on the Controller level and put the Action as a parameter
  • That Route will then be applied on all Actions in the Controller
  • Well,It's like this : [Route("{action=index}")]
      
       BookingController.cs

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

        // eg: /Booking/Show
        public ActionResult Show() { return View(); }

        // eg: /Booking/New
        public ActionResult New() { return View(); }

    }

Above Routes on Browser are as below