我有一个这样的对象:
var lot = { ID: 0, ... //various other attributes
SchemeInstanceList: [] }
创建后,我用另一个结构的对象填充 SchemeInstanceList 属性,如下所示:
lot.SchemeInstanceList.push({ ID: 0, LotID: 0, SchemeID: 18, LotPosition: 0})
到这里为止,一切都很好。现在我将批次对象发送到我的 ActionMethod,创建一个数据库条目。
$.ajax({
url: "/Lots/CreateSchemes",
data: lot
});
public ActionResult CreateSchemes(LotModel lot) {
... //store lot in database
}
ActionMethod 被调用并且lot 的值是正确的,SchemeInstanceList 中有条目。然而,所有这些条目的属性都为零,我看不出我做错了什么。
当我传递单个列表元素本身时,条目会正确显示:
$.ajax({
url: "/Lots/CreateScheme",
data: lot.SchemeInstanceList[0]
}
public ActionResult CreateScheme(SchemeInstanceModel scheme) {
... //do whatever
}
现在 SchemeID 的值是 18 而不是 0。
为什么这不起作用?我错过了什么最明显的事情?
编辑:这是我的模型:
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; }
}