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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -