3

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?

0

1 Answer 1

5

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

@Url.Action("Find", "Grid", new {ids= string.Join("&ids=", YourList)})
Sign up to request clarification or add additional context in comments.

1 Comment

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".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.