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
Post a Comment