I want to do this, but I want to also be able to pass in arrays into the query string. I\'ve tried things like:
http://www.sitename.com/route?arr[]=this&
I have found a solution. For example, if you have a query like this:
http://www.sitename.com/route?arr[]=this&arr[]=that
You must define in parameter as [FromQuery(Name = "arr[]")]
. The name of parameter must include square brackets. As result we can see:
public void DoSomething([FromQuery(Name = "arr[]")] string[] arr)
In the end, I just passed in a single delimited string, then used string.Split to separate on the server side. Not the prettiest solution, but it works. Until someone comes up with a better answer, this is all I got. I should reiterate that I'm using .NET Core, and these query strings are framework specific.
Update: An (arguable) benefit of this approach is that you pass the values together (e.g. arr=value1,value2) instead of repeating the key (arr=value1&arr=value2).