Search code examples
c#asp.net-mvcparametersactionmethod

Passing multiple parameter via GET with params keyword to an MVC controller action


Is there any way to pass multiple paramters by using params keyword to an action method with GET as below?

http://.../Method/param1/param2/param3/..../paramN

Action method should be as below:

public ActionResult Method(params string[] parameters)
{
//Do what ever.
}

Solution

  • If you need this for url routing you can use something like this:

    routes.MapRoute("Name", "param/{*params}", new { controller = ..., action = ... });
    
    ActionResult MyAction(string params) {
        foreach(string param in params.Split("/")) {
            ...
        }
    }