Telerik MVC 网格自定义命令更新网格
如何使用自定义命令更新 Telerik 网格?例如,下面我有一个按钮,可以通过自定义命令按钮将行的姓氏更新为 Peters。调用了操作方法,但网格未更新。
@Html.Telerik()
.Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.Phone);
columns.Bound(o => o.State);
columns.Command(commands => commands.Custom("Stuff")
.Text("Change Name")
.DataRouteValues(route => route.Add(o => o.LastName)
.RouteKey("lastName"))
.Ajax(true)
.Action("Stuff", "Home"));
})
.DataBinding(dataBinding =>
{
dataBinding.Server().Select("Index", "Home", new { ajax = ViewData["ajax"] });
dataBinding.Ajax().Select("_Index", "Home").Enabled((bool)ViewData["ajax"]);
})
.Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
.Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
.Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
.Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
.Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
.Footer((bool)ViewData["showFooter"]);
行动方法:
[GridAction]
public ActionResult Stuff(string lastName)
{
IEnumerable<Person> persons = GetPersons();
persons.First(p => p.LastName == lastName).LastName = "Peters";
return View(new GridModel(persons));
}
How do you make a custom command update the telerik grid? For example below I have a button that updates the Last Name for the row to Peters via a custom command button. The action method is called, but the grid is not updated.
@Html.Telerik()
.Grid(Model)
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.Phone);
columns.Bound(o => o.State);
columns.Command(commands => commands.Custom("Stuff")
.Text("Change Name")
.DataRouteValues(route => route.Add(o => o.LastName)
.RouteKey("lastName"))
.Ajax(true)
.Action("Stuff", "Home"));
})
.DataBinding(dataBinding =>
{
dataBinding.Server().Select("Index", "Home", new { ajax = ViewData["ajax"] });
dataBinding.Ajax().Select("_Index", "Home").Enabled((bool)ViewData["ajax"]);
})
.Scrollable(scrolling => scrolling.Enabled((bool)ViewData["scrolling"]))
.Sortable(sorting => sorting.Enabled((bool)ViewData["sorting"]))
.Pageable(paging => paging.Enabled((bool)ViewData["paging"]))
.Filterable(filtering => filtering.Enabled((bool)ViewData["filtering"]))
.Groupable(grouping => grouping.Enabled((bool)ViewData["grouping"]))
.Footer((bool)ViewData["showFooter"]);
Action Method:
[GridAction]
public ActionResult Stuff(string lastName)
{
IEnumerable<Person> persons = GetPersons();
persons.First(p => p.LastName == lastName).LastName = "Peters";
return View(new GridModel(persons));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加到 ClientEvents 网格。
添加 javascript 以重建网格(如果操作是 Stuff):
Add to ClientEvents grid.
Add javascript to rebuild the grid if action is Stuff: