I am trying to create a web API. As part of it I want to create a Get method which any accept any number of variable of a particular type.
public class MyController : ControllerBase
{
[HttpGet]
public int[] Get(int[] ids)
{
for(int i = 0; i < ids.Length; i++)
{
ids[i] = ids[i] * 100;
}
return ids;
}
}
When I try to make a get request from postman using
https://localhost:44363/api/executionstatus?ids=1&ids=2&ids=3
I get an error
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"|39f5d965-4240af31edd27f50.","errors":{"$":["The JSON value could not be converted to System.Int32[]. Path: $ | LineNumber: 0 | BytePositionInLine: 1."]}}
I have also tried with
https://localhost:44363/api/executionstatus?ids=1,2,3
but it is also resulting in the same error. What is the correct way to pass/handle multiple parameters from a get request?