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

, ,
  • Normally, the routes in a controller all start with the same prefix
  • Well,It's like this : /Booking

BookingController.cs

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

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

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


Above Routes on Browser are as below