Passing a list of int to a HttpGet request

If you are using MVC WebAPI, then you can declare your method like this:

[HttpGet]
public int GetTotalItemsInArray([FromQuery]int[] listOfIds)
{
       return listOfIds.Length;
}

and then you query like this:
blabla.com/GetTotalItemsInArray?listOfIds=1&listOfIds=2&listOfIds=3

this will match array [1, 2, 3] into listOfIds param (and return 3 as expected)

Leave a Comment

tech