Cloud Training (Online)




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();
}
Senthil Kumar B
Senthil Kumar is a former Microsoft MVP (Most Valuable Professional). He is a Co-Author of the book "Windows 10 Development Recipes using JavaScript and CSS" for Apress Publication. He is a technical presenter, blogger, mentor and a Geek.  Senthil is a regular speaker is various local user groups. He has presented at conferences like Great Indian Developer Summit (GIDS) & Microsoft DevCamps. You can reach out to him via his Twitter handle @isenthil.