c# - Change routeconfig -


in routeconfig-file see :

routes.maproute(     name: "default",     url: "{controller}/{action}/{id}",     defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); 

which maps in controller

public person get(int id) {     return _personservice.getpersoonbyinsznumber("11111111111"); } 

now change maps following :

public person get(string insznumber) {     return _personservice.getpersoonbyinsznumber(insznumber); } 

how can this?

it can done using attrubute routing:

[route("persons/get/{id:int}")] public person get(int id) {     .... }  [route("persons/get/{insznumber}")] public person get(string insznumber) {     .... } 

just add appropriate attributes (here i'm supposing controller name personscontroller. in other case change appropriately) actions.

also make sure have line of code in registerroutes method before default route declaration:

routes.mapmvcattributeroutes(); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -