Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer

its not elegant way... but simple and fast. Try

@Url.Action("Find", "Grid", new {ids= string.Join("&ids=", YourList)})
share|improve this answer
 
thanks, but it's exactly the kind of code I'm trying to avoid :) it always seems veery weird to me when you have to use hacks like this for something I'd call a "basic typical task". –  vorou Jun 13 at 16:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.