I have an array of strings that I need to pass in a query string of Url.Action.
Url.Action("Index", "Resource", new { FormatIds = Model.FormatIDs})
Right now the link is showing up in my browser as System.String[] instead of a query string. Is it possible to have MVC do this automatically with model binding?
I need it to bind with my controller action like:
public ActionResult Index(string[] formatIDs)
To get the list of string to automatically bind using the default binder, you will need to provide them as:
So you'll need to convert your list to something like:
There is another way using the RouteValueDictionary with an array:
usage:
Still not very elegant - but working.
For use the default model binder, you should end up with something like :
you can returns a private collection named HttpValueCollection even the documentation says it's a NameValueCollection using the ParseQueryString utility. Then add the keys manually, HttpValueCollection do the encoding for you. And then just append the QueryString manually :