Kendo MVC Grid: Creating a Custom command button and passing parameters

99封情书 提交于 2019-12-30 06:16:08

问题


I'm trying to create a custom command button to fire a custom delete function. I need to pass the ID of my model to my custom delete function. You'll notice that I'm trying to pass in a static '5' as a test but I would like to pass in the ID of the row.

Any help would be greatly appreciated.

@(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"))
))

回答1:


This should send any Data keys specified:

command.Custom("Delete").SendDataKeys(true).Click("PropertyPage.DeleteProperty");

DataKeys are specified in the DataSource section:

    .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"))

I also found this page on Kendo's site. It helped me out when I was having a similar issue: http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/migration/widgets/grid#editing

Hope this helps!



来源:https://stackoverflow.com/questions/13368269/kendo-mvc-grid-creating-a-custom-command-button-and-passing-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!