simple question:
I want to post some data to an action like this:
var data = {
Prop1 : 'a',
ListOfObjects: [{ PropertyA: 1, PropertyB: 2 }, { PropertyA: 3, PropertyB: 4}]
};
When I send this data to my Action via JQuery AJAX, my model is partially filled:
public class MyObject{
public int PropertyA {get;set;}
public int PropertyB {get;set;}
}
public class MyModel{
public string Prop1 {get;set;}
public List<MyObject> ListOfObjects {get;set;}
}
public JsonResult Save(MyModel model)
.
.
.
model.Prop1 //Is okay!
model.ListOfObjects[0] // is okay too...List has 2 items
model.ListOfObjects[0].PropertyA; //Nope...no values inside this model...
I guess the reason is, that the serialized HTTP Data are wrong, they are like ListOfObjects[0][PropertyA] <- but it should be ListOfObjkects[0].PropertyA
Does anyone know what to do?!
EDIT: My JQuery AJAX code:
$.ajax({
type: 'POST',
url: saveURL,
dataType: 'json',
data: data,
complete: function () {
DeleteMainLoader();
},
success: function success(data, textStatus, jqXHR) {
if (data.success) {
alert('win!')
}
else {
alert('error');
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('errrrrooooorrrr');
}
});