我有一个带有自定义命令按钮的 Telerik 网格,它应该复制一行。命令按钮调用 JsonResult 控制器方法。它复制了这条线并返回了模型,但网格没有改变——我认为因为它没有重新绑定。
我以为它会自动发生。
Html.Telerik().Grid<MerchantPageModel>()
.Name("PageChooserGrid")
.DataKeys(keys => keys
.Add(c => c.PageID)
.RouteKey("PageID"))
.Columns(cols =>
{
cols.Bound(c => c.Name).Width(300).ClientTemplate("<input type='text' name='name' value='<#= Name #>' readonly='true' />");
cols.Bound(c => c.Template).Width(400).ClientTemplate("<input type='text' name='template' value='<#= Template #>' readonly='true' />");
cols.Bound(c => c.Author).Width(100).ClientTemplate("<input type='text' name='author' value='<#= Author #>' readonly='true' />");
cols.Bound(c => c.ModifiedDate).Format("{0:MM/dd/yyyy}").Width(120).ClientTemplate("<input type='text' name='modifieddate' value='<#= ModifiedDate #>' readonly='true' />");
cols.Bound(c => c.IncludeInNav).ClientTemplate("<input type='checkbox' name='IncludeInNav' value='<#= IncludeInNav #>' <#= populateCheckboxes(IncludeInNav) #>' />")
.Title("Include In Nav")
.Width(100);
cols.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Text);
commands.Custom("Copy").Text("Copy").DataRouteValues(route => route.Add(o => o.PageID).RouteKey("PageID")).Ajax(true)
.Action("_AjaxCopyPage", "SetupWizard");
commands.Delete().ButtonType(GridButtonType.Text);
}).Title("Action List");
})
.DataBinding(data => data.Ajax()
.Select("_AjaxBinding", "SetupWizard")
.Update("_AjaxEditing", "SetupWizard")
.Delete("_AjaxDelete", "SetupWizard"))
.Pageable()
.Sortable()
.ClientEvents(events =>
{ events.OnComplete("Grid_onComplete");
events.OnCommand("Grid_onCommand");
events.OnDataBound("Grid_OnDataBound");
events.OnDataBinding("Grid_OnDataBinding");
})
.EnableCustomBinding(true)
.Render();
控制器返回:
return Json(pageModel.Pages, JsonRequestBehavior.AllowGet);