public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
public ActionResult Test (List<Person> persons)
{
...
}
Javascript:
var person = { Name: "P1", Id: 1 };
var persons = [];
persons.push(person);
persons.push(person);
var json = JSON.stringify(persons);
$.ajax({
url: '@Url.Action("Test")',
type: 'GET',
dataType: 'json',
data: json,
contentType: 'application/json; charset=utf-8',
});
I am trying to send a list of person objects to the controller using a GET request. The problem is that the persons list is always null. When I make a POST request everything works fine.
Is it possible to bind a list of complex json objects to a C# object using an ajax GET request?
Is it possible to bind a list of complex json objects to a C# object using an ajax GET request?
No, it isn't. Remember that there's a limit in the query string you could send, so having complex objects in a GET request is probably not something you should be doing anyway. The GET verb is normally used for retrieving data from simple things like an ID and a couple of other query string parameters, not by sending complex objects.
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.