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.

tereško
  • 58,060
  • 25
  • 98
  • 150
Mark13426
  • 2,569
  • 6
  • 41
  • 75

1 Answers1

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.

Maggie Ying
  • 10,095
  • 2
  • 33
  • 36
  • 2
    Thank you for this answer, it did help. The square brackets "[]" were unnecessary for me. – Onosa Jun 03 '14 at 17:26
  • 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 – Chris Surfleet Feb 18 '16 at 14:35
  • @ChrisSurfleet - too late to reply but are you sure you added List and not just string as the parameter type. – sandiejat Mar 20 '17 at 02:32