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

1

6

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.
}
Mutant answered 10/1, 2013 at 12:13 Comment(2)
Why do you need to do it that way? I guess you could implement your own model binder as long as the url routing allows for your mapping.Determined
Do need this for Url routing?Vaticide
S
3

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("/")) {
        ...
    }
}
Stafford answered 10/1, 2013 at 12:25 Comment(1)
Is it possible to sent int values to Action(params int[] arr) and then work with int array on server not with strings?Induna

© 2022 - 2024 — McMap. All rights reserved.