asp.net-mvc Kendo MVC Grid:创建自定义命令按钮并传递参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13368269/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Kendo MVC Grid: Creating a Custom command button and passing parameters
提问by Mithrilhall
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.
我正在尝试创建一个自定义命令按钮来触发自定义删除功能。我需要将模型的 ID 传递给我的自定义删除函数。你会注意到我试图传递一个静态的“5”作为测试,但我想传递行的 ID。
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"))
))
回答by Jark Monster
This should send any Data keys specified:
这应该发送指定的任何数据键:
command.Custom("Delete").SendDataKeys(true).Click("PropertyPage.DeleteProperty");
DataKeys are specified in the DataSource section:
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"))
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 的网站上找到了这个页面。当我遇到类似问题时,它帮助了我:http: //docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/migration/widgets/grid#editing
Hope this helps!
希望这可以帮助!

