Asp.net-Mvc

Kendo MVC Grid:創建自定義命令按鈕並傳遞參數

  • January 6, 2016

我正在嘗試創建一個自定義命令按鈕來觸發自定義刪除功能。我需要將模型的 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"))
))

這應該發送指定的任何數據鍵:

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

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

我還在 Kendo 的網站上找到了這個頁面。當我遇到類似問題時,它幫助了我: http ://docs.kendoui.c​​om/getting-started/using-kendo-with/aspnet-mvc/migration/widgets/grid#editing

希望這可以幫助!

引用自:https://stackoverflow.com/questions/13368269