I have an object like this:
var lot = { ID: 0, ... //various other attributes
SchemeInstanceList: [] }
After creation I fill the SchemeInstanceList attribute with objects of another structure like this:
lot.SchemeInstanceList.push({ ID: 0, LotID: 0, SchemeID: 18, LotPosition: 0})
Until here, everything is fine. Now I send the lot object to my ActionMethod, creating a database entry.
$.ajax({
url: "/Lots/CreateSchemes",
data: lot
});
public ActionResult CreateSchemes(LotModel lot) {
... //store lot in database
}
The ActionMethod gets called and the values of lot are correct, there are entries in the SchemeInstanceList. All of these entries' attributes are zero however and I don't see what I'm doing wrong.
When I pass a single list element itself, the entries appear correctly:
$.ajax({
url: "/Lots/CreateScheme",
data: lot.SchemeInstanceList[0]
}
public ActionResult CreateScheme(SchemeInstanceModel scheme) {
... //do whatever
}
Now the SchemeID value is 18 instead of 0.
Why isn't this working? What most obvious thing am I missing?
EDIT: Here are my models:
public class LotModel {
public int ID { get; set; }
... //various other properties
public List<SchemeInstanceModel> SchemeInstanceList { get; set; }
}
public class SchemeInstanceModel
{
public int ID { get; set; }
public int LotID { get; set; }
public int SchemeID { get; set; }
public int LotPosition { get; set; }
//public List<AttributeInstanceModel> AttributeInstanceList { get; set; }
}