想在Grid里面添加Edit的超链接,而Grid里面的数据使用的是Ajax Binding.
效果如下,问题是当翻页以后,Edit的超链接不见了.
如下:
页面浏览代码如下:
@( Html.Telerik().Grid(Model) .Name("Service") .Columns(columns => { columns.Bound(s => s.ServiceID).Hidden(true); columns.Bound(s => s.Title).Title("标题"); columns.Bound(s => s.Author).Title("作者"); columns.Bound(s => s.Remark).Title("备注"); columns.Template(o => @Html.ActionLink("Edit", "Edit", new { id = o.ServiceID }, null)).Title("Edit"); }).DataBinding(dataBinding => dataBinding.Ajax() .Select("_AJaxBinding", "Service")) .Pageable() .Sortable() )
Controller里面按照示例绑定,使用了ViewModel
public ViewResult Index() { var model = (from s in db.ServiceCases select new ServiceViewModel { ServiceID = s.ServiceID, Title = s.Title, Author = s.Author, Remark = s.Remark }).ToList(); return View(model); } [GridAction] public ActionResult _AjaxBinding() { var model = (from s in db.ServiceCases select new ServiceViewModel { ServiceID = s.ServiceID, Title = s.Title, Author = s.Author, Remark = s.Remark }).ToList(); return View(new GridModel { Data = model }); }
去文档查询,不知道如何下手.
怎么翻页的? 翻页代码贴出来。
翻页完成再做一次绑定应该可以了
public ViewResult Index() { var model = (from s in db.ServiceCases select new ServiceViewModel { ServiceID = s.ServiceID, Title = s.Title, Author = s.Author, Remark = s.Remark }).ToList(); return View(model); } [GridAction] public ActionResult _AjaxBinding() { var model = (from s in db.ServiceCases select new ServiceViewModel { ServiceID = s.ServiceID, Title = s.Title, Author = s.Author, Remark = s.Remark }).ToList(); return View(new GridModel { Data = model }); }
就是上面Controller里面的代码,就实现了绑定和翻页.使用的是Gird控件.
columns.Bound(p => p.Discontinued)
.ClientTemplate("<input type='checkbox' disabled='disabled' name='Discontinued' <#=
Discontinued? checked='checked' : '' #> />");
个人感觉,如果楼按照官网上例子来写的话,应该没有什么错误。
http://demos.telerik.com/aspnet-mvc/razor/grid/columncontextmenu
其实我的问题就是在使用Ajax Binding后,怎么添加编辑,删除列哈.我在看看文档在回复哈.
官网上的例子是服务器端绑定,添加删除操作在翻页后依然正常
但是使用AJAXJ绑定后,添加删除操作翻页后就不见了,这些添加删除操作都是自定义的操作.
要么用ClientTemplate,要么用Server 端绑定