我一直在我的子網格中顯示「No items to display」。 我有2個視圖模型,主人和名字。主人可以綁定多個姓名。 當我執行該頁面時,它會按預期顯示主信息。但是它的子項名稱沒有顯示任何項目,儘管當我在JSON上斷點時它包含它返回的2個名稱。無法加載網格中的分層數據。 0 items
Index.cshtml
@(
Html.Kendo().Grid(Model).Name("MainGrid")
.Columns(col =>
{
col.Bound(m => m.ListingId).Width(100);
col.Bound(m => m.Gender).Width(100);
})
.ClientDetailTemplateId("NameGridTemplate")
.Reorderable(reorder => reorder.Columns(true))
.Sortable()
.Scrollable()
.Filterable()
.Groupable()
.Pageable()
.DataSource(ds => ds
.Ajax()
.Model(m => m.Id(i => i.ListingId))
.Read(read => read.Action("HierarchyBinding_Master", "Main"))
)
.Events(events => events.DataBound("dataBound"))
)
<script id="NameGridTemplate" type="text/kendo-tmpl">
@(Html.Kendo().Grid<NameViewModel>()
.Name("grid_#=ListingId#") // template expression, to be evaluated in the master context
.Columns(columns =>
{
columns.Bound(o => o.PersonName).Width(110);
columns.Bound(o => o.Type).Width(110);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("HierarchyBinding_Name", "Main", new { listingId = "#=ListingId#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
</script>
<script>
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>
主ViewModal 公共類MasterViewModal {
public int ListingId { get; set; }
public String Gender { get; set; }
public int? Swn { get; set; }
public DateTime? SwnExpDate { get; set; }
public String Source { get; set; }
public Boolean PrStatus { get; set; }
public String PrCountry { get; set; }
public Boolean PermanentBan { get; set; }
public String BanIssueAgency { get; set; }
}
NameViewModal public class NameViewModel public int ListingId {get;組; } public String PersonName {get;組; } public String Type {get;組; } public DateTime DateLastUpd {get;私人設置; } public String UserLastUpd {get;私人設置; }}
主控制器 公共類MainController:控制器 {
ListingContext db = new ListingContext();
public ActionResult Index()
{
List<Master> dataList = null;
dataList = db.Masters.ToList();
List<MasterViewModal> mvmList = Logic.GetMasterViewModels(dataList);
return View(mvmList);
}
public ActionResult HierarchyBinding_Master([DataSourceRequest] DataSourceRequest request)
{
List<Master> masterList = null;
masterList = db.Masters.ToList();
return Json(Logic.GetMasterViewModels(masterList));
}
public ActionResult HierarchyBinding_Name(int listingId, [DataSourceRequest] DataSourceRequest request)
{
List<Name> nameList = null;
nameList = db.Names.ToList();
JsonResult j = Json(nameList
.Where(name => name.ListingId == listingId)
.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
return j;
}
}