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

  1. how configure route passes either request same action method on same controller

  2. 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

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -