I have an ASP.NET Web API (version 4) REST service where I need to pass an array of integers.
Here is my action method:
Easy way to send array params to web api
API
public IEnumerable GetCategories([FromUri]int[] categoryIds){
// code to retrieve categories from database
}
Jquery : send JSON object as request params
$.get('api/categories/GetCategories',{categoryIds:[1,2,3,4]}).done(function(response){
console.log(response);
//success response
});
It will generate your request URL like
../api/categories/GetCategories?categoryIds=1&categoryIds=2&categoryIds=3&categoryIds=4