ProgrammerGuide.Net | Step by Step Programmer Guide

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



Please click here for related products on Amazon!

Jayashee

Add comment

Want to Check Celebrities News?