Passing Array of Integers to ASP.NET Web API REST Service

You can pass an array of integer to an ASP.NET Web Web API REST service by setting the [FromUri] attribute for the parameter of the action method.

How to pass an array of integer to ASP.NET Web API REST Service?

Assume that you want to access the Employees with the id’s 1,2,3 and you would like to pass them in the parameter of the URL and retreive this as the array of integers in the action method. Here’s how your action method will look like.

public IHttpActionResult GetEmployees([FromUri] int[] employeeIds)
{
    return Ok();
}

Leave a Reply

Your email address will not be published. Required fields are marked *