Reputation: 752
Using Visual Studio 2012.2, MVC4 web application.
I have requests coming to my ApiController like so:
http://localhost/api/keys?ids[]=1&ids[]=2&ids[]=3
And I was under the impression that the following method should be able to automagically retrieve the values from the ids[] array:
public KeysModel Get(int[] ids){...}
However, when a request like the one above comes in, the value of the "ids" parameter is null.
I have inspected that HttpContext.Current.Request.QueryString has the values for ids, and I could get to them that way, but that makes unit testing harder.
I have also tried using List ids, [FromUri], [FromUri(Name="ids[]")], object ids, and string ids (interesting note... when ids is a string variable, the value within it is "(Collection)"
Upvotes: 3
Views: 1576
Reputation: 752
Turns out:
public KeysModel Get([FromUri]int[] ids){...}
Was the answer after all.
Dunno what I was doing before...
Upvotes: 5