I'm currently working on an issue sending JSON data to My Controller.
I found out that when Passing an Object, which Contains a nested one, the nested object will be null. I can't figure out what I'm missing...
My serverside looks like this:
[HttpPost]
public ActionResult ApplyChanges(List<Change> pChanges)
{
//the Issue occurs here in every object of pChanges:
//IgnoreFlag was populated correctly, but the Detection Object is null...?
}
public class Change
{
public Detection Detection { get; set; }
public bool IgnoreFlag { get; set; }
}
My Clientside looks like this:
var data = [
{
"Detection": {
"PropertyOld": 1,
"PropertyNew": 2,
},
"IgnoreFlag": true
},
{
"Detection": {
"PropertyOld": 3,
"PropertyNew": 4,
},
"IgnoreFlag": false
}
]
$.ajax({
type: "POST",
url: "/Url/To/ApplyChanges",
data: JSON.stringify({"pChanges": data}),
contentType: "application/json",
success: function (data, textStatus, jqXHR) {
//do something here
});
Can someone help me to solve this issue?
JSON.stringifyyour object. jsfiddle.net/qz3vp6gxJSON.stringifyis ignoring something. I'm just showing that it doesn't ignore anything. Based on the client-side code you provided, there's nothing wrong. Not sure what the server-side issue may be.