我有一个用 ClientDetailTemplate 定义的分层网格,如下所示。
@(Html.Kendo().Grid(Model.NotesList) //Bind the grid to NotesList
.Name("activityNotesGrid")
.Columns(columns =>
{
// Create a column bound to the Date property
columns
.Bound(n => n.Date)
.Title("DATE")
.Format("{0:MM/dd/yyyy}");
// Create a column bound to the Author property
columns
.Bound(n => n.Author)
.Title("ADDED BY");
})
.Filterable()
.Sortable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(true)
)
.Events(events => events.DataBound("grid_dataBound"))
.ClientDetailTemplateId("threadedNotesTemplate")
)
<script id="threadedNotesTemplate" type="text/kendo-tmpl" class=".k-grid-header">
@(Html.Kendo().Grid<ActivityThreadedNoteModel>()
.Name("grid_#=NoteId#")
//.Animation(animation => animation.Open(open => open.Fade(FadeDirection.In)))
.Columns(columns =>
{
//columns
// .Bound(p => p.RegistryId)
// .Title("RegistryId");
//columns
// .Bound(p => p.RegistryDisplayName)
// .Title("Registry");
columns
.Bound(p => p.Date)
.Format("{0:MM/dd/yyyy}");
//.Title("Care Guideline");
columns
.Bound(p => p.Author);
columns
.Bound(p => p.NoteType);
//.Title("Process Status");
//.Title("Outcome Status");
columns
.Bound(p => p.Note);
columns
.Bound(p => p.NoteDetailsId)
.ClientTemplate(
"# if (ShowInOverview == true) { #" +
"<i><a href='" + Url.Action(Constants.Actions.Show_HideInOverview_Note, Constants.Controllers.PatientActivity) + "?**NoteDetailsId**= #=item.NoteDetailsId #&showInOverview=false'" + ">" + Medventive.Registry.UI.Web.Resources.RegistryMVCWeb.HideInOverview + "</a></i>" +
"# } else { #" +
"<i><a href='" + Url.Action(Constants.Actions.Show_HideInOverview_Note, Constants.Controllers.PatientActivity) + "?NoteDetailsId= #=item.NoteDetailsId #&showInOverview=true'" + ">" + Medventive.Registry.UI.Web.Resources.RegistryMVCWeb.HideInOverview + "</a></i>" +
"# } #"
);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action(Constants.Actions.LoadPatientThreadedNotes, Constants.Controllers.PatientActivity, new { NoteId = "#=NoteId#" }))
)
.Pageable()
.Sortable()
.ToClientTemplate()
)
</script>
在运行时,我收到一个javascript错误。NoteDetailsId 未定义。我需要将 ID 传递给操作/控制器。我的视图模型中确实有 NoteDetailsId 属性,并且在模型中有一个值。
我是剑道的新手,希望能在这里得到任何帮助。
有趣的是,对于 kendo 分层网格,它会在 ajax 调用时从服务器获取值之前尝试呈现网格。
我通过在 ajax 调用中将 id 值传递给子网格来解决上述问题,在渲染它们时使用 kendo grid 自定义命令和 jquery 在单击子项的相应链接时调用控制器。