views:

73

answers:

2

Hi all,

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

+3  A: 

Try ?amenityTypes=1&amenityTypes=5.

earl
+3  A: 

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.

David Neale
fixed the link to Phil Haack's blog :)
Russ Cam
That's true for the general case. It should work for primitive types (such as `int`), though, as is also mentioned in the blog post you point to.
earl
Nice one, thanks. Was trying to answer from my phone but can't work out how to copy URLs on it! Will stick to laptop in future.
David Neale
@earl. Good point, I hadn't realised the default model binder did that, the blog confirms it does as well. +1.
David Neale
Denis Hoctor