views:

30

answers:

1

I would like different a different action to handle a request depending on query parameters values.

For example:

mydomain.com/controller/action?version=1&msg=hello

and

mydomain.com/controller/action?version=2&msg=5

should go to a different handlers based on the version value.

The list of query params required/optional, as well as their types might change - in version=1, msg is a string, in version=2 it is an integer

+2  A: 

You could use Route Constraints:

routes.MapRoute("first", "/controller/action/{version}/{msg}", 
    new {controller = "controller", action = "action", 
        version = String.Empty, msg = String.Empty},
    new {version = "1"});

routes.MapRoute("first", "/controller/action/{version}/{msg}", 
    new {controller = "controller", action = "action2", 
        version = String.Empty, msg = String.Empty},
    new {version = "2"});
Yuriy Faktorovich