Passing through lists from jQuery to the service
- by thedixon
I'm sure I've done this in another solution, but I can't seem to find any solution as to do it again and wondered if anyone can help me...
This is my WebAPI code:
public class WebController : ApiController
{
public void Get(string telephone, string postcode, List<Client> clients)
{
}
}
And, calling this from jQuery:
function Client(name, age) {
this.Name = name;
this.Age = age;
}
var Clients = [];
Clients.push(new Client("Chris", 27));
$.ajax({
url: "/api/Web/",
data: { telephone: "999", postcode: "xxx xxx", clients: Clients }
});
But the "clients" object always comes back as null. I've also tried JSON.stringify(Clients), and this is the same result. Can anyone see anything obvious I'm missing here?