简体   繁体   中英

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.

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM