我一直在"没有要显示的项目"在我的孩子网格。 我有2个视图模型,Master和Name。 Master可以绑定多个Name。 当我执行页面时,它会按预期显示主信息。但它的子名称没有显示任何项目,但是当我在JSON上断点时它包含2个返回的名称。
的 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>
Master 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
公共类NameViewModel
{
public int ListingId {get;组; }
public String PersonName {get;组; }
public String Type {get;组; }
public DateTime DateLastUpd {get;私人集; }
public String UserLastUpd {get;私人集; }
}
主控制器
public class MainController:Controller
{
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 :(得分: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。
我认为它会起作用。我没有看到你的剃刀代码有什么问题