Kendo MVC Grid:创建自定义命令按钮并传递参数

Mit*_*all 9 asp.net-mvc grid telerik kendo-ui

我正在尝试创建一个自定义命令按钮来触发自定义删除功能.我需要将模型的ID传递给我的自定义删除功能.您会注意到我正在尝试传入一个静态的'5'作为测试,但我想传入该行的ID.

任何帮助将不胜感激.

@(Html.Kendo().Grid(Model)
.Name("Grid")
.Columns(columns =>
{
    columns.Bound(p => p.Name).Width(240);
    columns.Bound(p => p.City).Width(170);
    columns.Bound(p => p.State).Width(170);
    columns.Command(command =>
    {
        command.Edit();
        command.Custom("Delete").Click("PropertyPage.DeleteProperty").HtmlAttributes(new { @Id = 5 });
        }).Width(166);
    })
    .Scrollable()
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model => model.Id(p => p.Id))
        .Read(read => read.Action("PropertyRead", "Property"))
        .Update(update => update.Action("Update", "Property"))
        .Destroy(update => update.Action("Delete", "Property"))
))
Run Code Online (Sandbox Code Playgroud)

Jar*_*ter 12

这应该发送指定的任何数据键:

command.Custom("Delete").SendDataKeys(true).Click("PropertyPage.DeleteProperty");
Run Code Online (Sandbox Code Playgroud)

DataKeys在DataSource部分中指定:

    .DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(p => p.Id))  // THIS IS YOUR DATA KEY
    .Read(read => read.Action("PropertyRead", "Property"))
    .Update(update => update.Action("Update", "Property"))
    .Destroy(update => update.Action("Delete", "Property"))
Run Code Online (Sandbox Code Playgroud)

我也在剑道的网站上找到了这个页面.当我遇到类似的问题时,它帮助了我:http: //docs.kendoui.c​​om/getting-started/using-kendo-with/aspnet-mvc/migration/widgets/grid#editing

希望这可以帮助!

  • 我的错.我没有意识到这是一个调用javascript函数.抱歉! 考虑到这一点,将自定义命令语法更改为:command.Custom("Delete").单击("PropertyPage.DeleteProperty"); 你的函数应如下所示:function DeleteProperty(e){//或者你的函数名是var dataItem = this.dataItem($(e.currentTarget).closest("tr")); var id = dataItem.Id; 警报(ID); } (8认同)
  • 如何在我的函数DeleteProperty中访问该datakey?函数DeleteProperty(e)...我尝试了一个警报(e),我所看到的只是对象.我需要获得Id. (2认同)