Add optional parameter with url in mvc3

I am new to asp.net mvc3. I want to add an additional parameter with url in front of the controller, for example: -

Newparameter/{controller}/{action}/{id}; 

it is possible, and I need to change its value.

Please, help....

+4
source share
2 answers

Yes, maybe just add a new route to your Global.asax as follows:

 routes.MapRoute( "Default with new param", // Route name "{newParameter}/{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); 

Put this in front of the default route, as it is more specific.

Then create an action method that takes the newParameter parameter as the method parameter

+5
source

you will need to define a new route in Global.ascx , for example

 routes.MapRoute( "RouteName", "{Param}/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); 

and don't forget to put the new route above the default route.

+1
source

Source: https://habr.com/ru/post/1445054/


All Articles