I would like to pass an array of IDs to a controller. Originally I was adding each ID in the query string like so:
http://localhost:4000/customers/active?customerId=1&customerId=2&customerId=3
Then on the controller side I had a method that would accept the array like this:
GetCustomers([FromQuery] int[] ids)
{
...
}
This was working well but there are a few situations where there are so many customerIds
in the array that the query string became too long so I had to modify the way that the query was being passed to this:
http://localhost:4000/customers/active?customerIds=1,2,3
I got the solution working by changing GetCustomers
params to accept a string instead of an int array and then parsed the customerIds
out in the controller (using .Split(',')
)
I feel like it was cleaner to pass an array directly instead of having to modify the string on the server side. Is there a way to achieve this given the way the customerIds
are now being passed?