Kieran
Kieran

Reputation: 656

Web Api passing a list as a URL paramater issues

One of the methods that I am calling requires a list to function. Therefore I need to pass an list of values into the URL when calling the method.

I have found a few similar questions online but none of the solutions seem to be working for me.

The following is the method signature I am currently using:

public List<StationPlace> PlacesList(string[] list) {

And these are a few of the ways I have been trying to specify the list in the URL:

? list = "x", "y"
? list = ["x", "y"]
? list = new string[] {"x", "y"}

Really just guessing at this point.

Whenever I debug list is null in the execution.

Thanks.

P.S. Is there also a way to pass values in for a generic list instead of an array?

Upvotes: 2

Views: 614

Answers (1)

Simon Karlsson
Simon Karlsson

Reputation: 4129

You are fairly close try changing your url to:

?list=x&list=y

That should give you a list of ["x", "y"]

This also works for:

public List<StationPlace> PlacesList([FromUri] List<string> list)

Upvotes: 3

Related Questions