0

我一直在我的子网格中显示“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; 
     } 


    } 

回答

0

请试试这个

public ActionResult HierarchyBinding_Name(int listingId, [DataSourceRequest] DataSourceRequest request) 
{ 
    List<Name> nameList = null; 
    nameList = db.Names.ToList(); 

    return Json(nameList 
     .Where(name => name.ListingId == listingId) 
     .ToDataSourceResult(request)); 
} 

取出Jsonrequestbehaviour.Allowget。

我认为它会工作。我没有看到你的剃刀代码有任何问题