我有一个Kendo Grid和一个网格的数据源,它将一堆行绑定到它。正在为数据源传输的每一行都是具有导航属性的模型。但是,当我创建一个新行并使用默认的kendo" save"对于网格的功能,导航属性未初始化。我需要能够在我的网格中为导航属性创建一个新表。我有以下设置。
$('#grid').kendoGrid({
dataSource: viewmodel.model.AChecklistCompleteSource,
filterable: true,
sortable: true,
pageable: true,
columns: [{
field: "createdBy",
title: "Created By",
width: 200
},
{
field: "dateCreated",
title: "Date Created"
},
{
field: "dateModified",
title: "Date Modified"
},
{ command: { text: "View Checklist", click: viewmodel.model.showDetails }, title: " ", width: "180px" }
],
toolbar: [{ name: "create", text: "Create Checklist" }, { name: "save", text: "Save Checklist" }, "cancel"],
editable: "inline",
saveChanges: function (e) {
//How do I manually save here so that my navigation property is not null for this row's model?
if (!confirm("Are you sure you want to save all changes?")) {
e.preventDefault();
}
},
height: 500
});
修改
这是我的实体框架代码第一个模型,它有两个导航属性,当kendo网格创建一个新行时为null:
public partial class AChecklistComplete
{
[Key]
public int AChecklistCompleteID { get; set; }
public string createdBy { get; set; }
public DateTime dateCreated { get; set; }
public DateTime dateModified { get; set; }
public virtual ChecklistTop AChecklistTop { get; set; }
public virtual Aircraft Aircraft { get; set; }
}
我的AChecklistCompleteSource只列出了这些模型。当kendo创建一个新行时,它允许我使用此模型创建并保存一行,但Aircraft和AChecklistTop为空,我想手动初始化它们(或者如果可能的话自动),以便我可以在我的表单上绑定它们在某些时候(即somefield = AChecklistComplete.Aircraft.SomeField)