我有一个网格,我希望能够删除行,而不必从控制器操作返回新的结果集。
这在我看来:
@(Html.Telerik().Grid<InterestTopicViewModel>()
.Name("Grid")
.DataKeys(keys => keys.Add(x => x.Id))
.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.Image).ImageHtmlAttributes(new {style="margin-left:0"}))
.DataBinding(dataBinding => dataBinding.Ajax()
.Select("Select", "InterestTopic")
.Insert("Insert", "InterestTopic")
.Update("Update", "InterestTopic")
.Delete("Delete", "InterestTopic"))
.Columns(columns =>
{
columns.Bound(x => x.Name);
columns.Command(commands =>
{
commands.Edit().ButtonType(GridButtonType.Image);
commands.Delete().ButtonType(GridButtonType.Image);
}).Title("Actions");
})
.Editable(editing => editing.Mode(GridEditMode.InLine))
)
这是在我的控制器中:
[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult Delete(int id)
{
InterestTopicViewModel interestTopicViewModel = this.InterestTopicPresenter.GetInterestTopic(id);
if (this.InterestTopicPresenter.DeleteInterestTopic(id))
base.LogUserAction(UserActionLoggingType.DeleteInterest, interestTopicViewModel.Name);
return this.View(new GridModel(this.InterestTopicPresenter.GetList()));
}
如您所见,在我的控制器中,我必须在函数末尾返回 GridModel 对象中的整个列表。如果我不这样做,视图将不会刷新。
是否可以在控制器的帮助下删除记录并让 Telerik 在 javascript 中删除相应行的 div?
谢谢你。