I have an MVC Web API Get method that accepts a List<string> as a parameter. I'm trying to access this method using simply the browser bar. How is this done? Using ../APIName?parameter1=value1¶meter2=value2&... passes a single parameter between two ampersands as opposed to a list.
Add a comment
|
1 Answer
Make sure your parameter of your action method is marked as [FromUri]. By default the value is expected to be passed from the body of the request since it is a complex type.
public List<string> Get([FromUri] List<string> parameter) {...}The query string parameter should be of this format
.../APIName?parameter[]=value1¶meter[]=value2&....
Hope this helps.
3 Comments
Onosa
Thank you for this answer, it did help. The square brackets "[]" were unnecessary for me.
Chris Surfleet
This isn't working for me. It works with the first 'parameter' call (with or without square brackets), but as soon as I add the second I just get a 500 message back from the server with no additional info, and no breakpoint hit in VS
sandiejat
@ChrisSurfleet - too late to reply but are you sure you added List<string> and not just string as the parameter type.