ProgrammerGuide.Net | Step by Step Programmer Guide

How to Set Common Route Prefix? | ASP.Net MVC Interview Question

  • If you want, you can specify a common prefix for an entire controller
  • To that you can use [RoutePrefix] attribute
  • It’s like this : [RoutePrefix(“Booking”)]

    public class BookingController : Controller
        // eg: /Booking
        public ActionResult Index() { return View(); }
        // eg: /Booking/5
        public ActionResult Show(int bookId) { return View(); }
        // eg: /Booking/5/Edit
        public ActionResult Edit(int bookId) { return View(); }

Above Routes on Browser are as below

Please click here for related products on Amazon!


Add comment

Want to Check Celebrities News?