HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpCritical

Pass an array of integers to ASP.NET Web API?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
netarrayaspapiwebintegerspass

Problem

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 GetCategories(int[] categoryIds){
// code to retrieve categories from database
}


And this is the URL that I have tried:

/Categories?categoryids=1,2,3,4

Solution

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

GetCategories([FromUri] int[] categoryIds)


And send request:

/Categories?categoryids=1&categoryids=2&categoryids=3

Code Snippets

/Categories?categoryids=1&categoryids=2&categoryids=3

Context

Stack Overflow Q#9981330, score: 755

Revisions (0)

No revisions yet.