C# – Pass an array of integers to ASP.NET Web API


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:

public IEnumerable<Category> GetCategories(int[] categoryIds){
// code to retrieve categories from database

And this is the URL that I have tried:


Best Solution

You just need to add [FromUri] before parameter, looks like:

GetCategories([FromUri] int[] categoryIds)

And send request: