patterncsharpCritical
Pass an array of integers to ASP.NET Web API?
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:
And this is the URL that I have tried:
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
And send request:
[FromUri] before parameter, looks like:GetCategories([FromUri] int[] categoryIds)
And send request:
/Categories?categoryids=1&categoryids=2&categoryids=3Code Snippets
/Categories?categoryids=1&categoryids=2&categoryids=3Context
Stack Overflow Q#9981330, score: 755
Revisions (0)
No revisions yet.