Reputation: 3494
I'm following all of the documentation I can find for binding a querystring parameter to an action parameter of type int[], but my array is always empty.
To repro: Spin up a vanilla aspnet core web application, ASP.NET Core 2.1, API template project, and modify the default ValuesController by adding the following action:
[HttpGet("count")]
public ActionResult<int> GetCountOfItems([FromQuery]int[] number)
{
return number.Count();
}
Calling this action like so:
GET /values/count?number=1&number=2
Should return 2, but always ends up 0.
Any ideas outside of creating custom model binders?
Upvotes: 1
Views: 1064
Reputation: 3494
Until the proper patch is rolled out, you can specify the name argument for the FromQuery attribute constructor.
[FromQuery(Name="number")]
Leaving this as the answer until then
Upvotes: 1
Reputation: 71
This has been fixed and will ship with the next patch. You can see the issue here for more detail: https://github.com/aspnet/Mvc/issues/7712
Upvotes: 1