24

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&parameter2=value2&... passes a single parameter between two ampersands as opposed to a list.

1 Answer 1

40
  1. 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)
    {...}
    
  2. The query string parameter should be of this format .../APIName?parameter[]=value1&parameter[]=value2&....

Hope this helps.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for this answer, it did help. The square brackets "[]" were unnecessary for me.
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
@ChrisSurfleet - too late to reply but are you sure you added List<string> and not just string as the parameter type.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.