Kendo MVC Grid:创建自定义命令按钮并传递参数 [英] Kendo MVC Grid: Creating a Custom command button and passing parameters

查看:17
本文介绍了Kendo MVC Grid:创建自定义命令按钮并传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

任何帮助将不胜感激.

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

推荐答案

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

This should send any Data keys specified:

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

DataKeys 在 DataSource 部分中指定:

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

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

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

希望这有帮助!

这篇关于Kendo MVC Grid:创建自定义命令按钮并传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆