Reputation: 1909
I have a controller's action:
public ActionResult Find(IEnumerable<string> ids) { ... }
I'm succesfully invoking it by route ../Find?ids=01&ids=02&ids=03
. DefaultModelBinder
easily binds the parameter with no extra configuration.
However, when I'm trying to do outbound routing, i.e. use code like this in my View
@Url.Action("Find", "Grid", new {ids=new List<string>{01,02,03}})
.. I'm getting a nice ..?ids=System.Collections.Generic.List1[System.String]
querystring in my URL. I've already found some answers which suggest writing an custom binding/routing, but I believe such a simple task should be solved much easier without any extra code.
P.S.: I'd be perfectly happy to change my querystring format, I just want to rely on some default framework behavior to accomplish the task: pass an array in querystring.
Short version: what is the most simple way to render a link to a controller's action with an array in querystring?
Upvotes: 3
Views: 2228
Reputation: 2284
its not elegant way... but simple and fast. Try
@Url.Action("Find", "Grid", new {ids= string.Join("&ids=", YourList)})
Upvotes: 5