-1

I have a typical ASP.NET MVC controller, but I just want to change its route. The default route now is:

Blog/{controller}/{action}/{id}

I want to change the route of a specific controller to

Blog/Admin/{controller}/{action}/{id}"

I tried to achieve this by adding the Route, RouteArea and RoutePrefix attributes to the controller but without any success.

How can I achieve this?

Anik Saha
  • 4,313
  • 2
  • 26
  • 41
Yulian
  • 6,262
  • 10
  • 65
  • 92

1 Answers1

1

Add this route prior to the default

routes.MapRoute(
                name: "BlogAdmin",
                url: "Blog/Admin/{action}/{id}",
                defaults: new { controller = "YourSpecificControllerName", action = "Index or other default action name", id= UrlParameter.Optional });

Since this is for a specific you don't need {controller} part in your url. If you still want to specify it change the url argument to "Blog/Admin/YourSpecificControllerName/{action}/{id}" where YourSpecificControllerName is the name of your controller. Also since the order of rote registration matters make sure that this route registered prior to the the default one

Alex Art.
  • 8,711
  • 3
  • 29
  • 47