Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I pass a querystring that translates to a List<int> on the server?

I'm writing a Google Maps app that requests data from the server using jQuery's $.ajax() to send the request to my ASP.Net MVC Contoller. This control expects a List for the amenity types. What should the querystring look like for this?

I've tried

http://localhost:9090/mapamenities?amenityTypes=1,5

http://localhost:9090/mapamenities?amenityTypes=[1,5]

with no luck.

The SearchRquest attribute I'm trying to bind to is

public List<int> AmenityTypes { get; set; }

Thanks Denis

like image 559
Denis Hoctor Avatar asked Jun 13 '10 16:06

Denis Hoctor


2 Answers

Try ?amenityTypes=1&amenityTypes=5.

like image 119
earl Avatar answered Sep 23 '22 20:09

earl


The default MVC model binder will handle primitive collections as per earl's answer. If you have any need to bind complex types take a look at this project.

like image 20
David Neale Avatar answered Sep 19 '22 20:09

David Neale