c# - Binding querystring values to a dictionary -


i'm using web api (part of asp.net mvc 5), , i'm trying bind querystring values dictionary<int, bool>.

my web api method simply:

[httpget] [route("api/items")] public iqueryable<item> getitems(dictionary<int, bool> cf) {     // ... } 

if try invoke url:

/api/items?cf[1009]=true&cf[1011]=true&cf[1012]=false&cf[1015]=true 

the parameter cf null.

how can pass in dictionary of values via querystring web api method?

there no built-in way of doing this. on case, "cf[1009]" name of parameter, not "cf". can write own query string parser achieve need. better signature be:

/api/items?cf=1009&cf=1011&cf=1015 

and bind using:

public iqueryable<item> getitems(list<int> cf) {     // ... } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -