asp.net mvc - How would I create an MVC route that directs all requests to a single method on a single controller and resolve the route parameter as {id}? -
given following examples
http://my.url/123 or http://my.url/abc
how configure route passes either request same action method on same controller
how resolve 123 or abc input paramter (id) action method
public actionresult index(string id) { viewdata["message"] = id; return view(); }
so if went http://my.url/123 print "123", etc.
thanks in advance!
the following work, may break other routes you're doing catch-all on first part of path:
routes.maproute( name: "id-route", url: "{id}", defaults: new { controller = "yourcontroller", action = "youraction", id = "{id}" });
Comments
Post a Comment