asp.net mvc 3 - URL Routing: How do I have a string as my id? -


i receive string id in url. here example:

http://www.example.com/home/portal/fishing 

i have fishing in id. cannot achieve following code:

code controller:

public actionresult portal(string name) {     // code     viewdata["portal name"] = name; } 

code global.asax.cs:

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

just change argument id:

public actionresult portal(string id) {     // code     viewdata["portal name"] = id; } 

the argument bound if has same name route value token. alternate approach keep argument named name , change route:

public actionresult portal(string name) {     // code     viewdata["portal name"] = name; }  routes.maproute(     "default", // route name     "{controller}/{action}/{name}", // url parameters     new { controller = "home", action = "index", name = urlparameter.optional } // parameter defaults ); 

i choose using id, though, it's more standard approach.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -