Telerik mvc 网格和自定义命令
使用 Telerik mvc grid 和 ajax,让我有些头疼。 我试图插入带有一些简单链接的列,以执行与删除命令相同的行为(因为我只是不想要默认命令列)。 但我失败了。 默认的删除命令效果很好:删除记录并刷新网格。 我的自定义链接,只删除记录,但网格不刷新。
这是我的代码。也许我错过了一件简单的事情。
视图:
@model Benner.Saude.Mapeamento.Especialidade[]
@(Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys => keys.Add(c => c.Handle))
.DataBinding(dataBinding => dataBinding
.Ajax()
.OperationMode(GridOperationMode.Client)
.Select("AjaxPesquisar", "Especialidade")
.Update("AjaxAtualizar", "Especialidade")
.Delete("Delete", "Especialidade"))
.HtmlAttributes(new { @class = "grid-padrao" })
.ClientEvents(events => events
.OnDataBound("atualizarCss")
)
.Columns(columns =>
{
.ClientTemplate("<text><a href='/Especialidade/Delete/33' class='formatacao delete-link' image='delete'/></text>")
.Width(20).Title("Commands"); ***this does not works ***
columns.Bound("Descricao").Title("Descrição");
columns.Bound("Handle").Title("Código");
columns.Command(commands =>
{
commands.Delete().ButtonType(GridButtonType.BareImage); ***this works***
}).Width(70);
})
.Pageable()
.Sortable()
)
控制器:
[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
[GridAction]
public ActionResult Delete(int id)
{
cadastro.ExcluirEspecialidade(Session["token"].ToString(), id);
Especialidade[] especialidades = consulta.PesquisarEspecialidades(Session["token"].ToString());
return View(new GridModel(especialidades));
}
JavaScript:
$("a.delete-link").click(function (event) {
var link = $(this)[0];
if (confirm("Confirm delete?")) {
$.post(link.href);
}
return false;
});
Using telerik mvc grid with ajax, give me some headaches.
I am trying to insert a column with some simple links, to perform the same behaviors that Delete command does (because I just don't want the default command column).
But I am fail.
The default Delete command works great: delete the record and refresh the grid.
My custom link, only delete the record, but the grid is not refreshed.
Here is my code. Maybe I am missing a simple thing.
View:
@model Benner.Saude.Mapeamento.Especialidade[]
@(Html.Telerik().Grid(Model)
.Name("Grid")
.DataKeys(keys => keys.Add(c => c.Handle))
.DataBinding(dataBinding => dataBinding
.Ajax()
.OperationMode(GridOperationMode.Client)
.Select("AjaxPesquisar", "Especialidade")
.Update("AjaxAtualizar", "Especialidade")
.Delete("Delete", "Especialidade"))
.HtmlAttributes(new { @class = "grid-padrao" })
.ClientEvents(events => events
.OnDataBound("atualizarCss")
)
.Columns(columns =>
{
.ClientTemplate("<text><a href='/Especialidade/Delete/33' class='formatacao delete-link' image='delete'/></text>")
.Width(20).Title("Commands"); ***this does not works ***
columns.Bound("Descricao").Title("Descrição");
columns.Bound("Handle").Title("Código");
columns.Command(commands =>
{
commands.Delete().ButtonType(GridButtonType.BareImage); ***this works***
}).Width(70);
})
.Pageable()
.Sortable()
)
Controller:
[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
[GridAction]
public ActionResult Delete(int id)
{
cadastro.ExcluirEspecialidade(Session["token"].ToString(), id);
Especialidade[] especialidades = consulta.PesquisarEspecialidades(Session["token"].ToString());
return View(new GridModel(especialidades));
}
Javascript:
$("a.delete-link").click(function (event) {
var link = $(this)[0];
if (confirm("Confirm delete?")) {
$.post(link.href);
}
return false;
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须获取网格对象并在ajax回调中调用重新绑定,例如
在
$("#Grid")
中“Grid”是页面上网格控件的名称。其余的是语法you have to get grid object and call rebind in ajax callback like
In
$("#Grid")
"Grid" is name of your grid control on the page. rest is syntax