如何将所选Kendo网格行的ID传递给控制器​​?

时间:2014-07-11 11:42:07

标签: asp.net-mvc kendo-grid

我有一个带有Kendo网格的MVC 4项目。网格是多选的。如何在按钮单击时将所选行的ID传递给控制器​​?

感谢。

这是我的网格:

    @(Html.Kendo().Grid(Model.Manifest)
      .Name("PackageGrid")
      .Columns(columns =>
      {
          columns.Bound(p=>p.PackageId).Hidden();
          columns.Bound(p => p.PackageName)
              .Template(@<text>@Html.ActionLink(@item.PackageName,"PackageDetails","ExternalIntegration", new {id=@item.PackageId}, null)</text>);
          columns.Bound(p => p.NumberOfDaysAgo);
          columns.Bound(p => p.LastEvent);
          columns.Bound(p=>p.ProcessDate);
          columns.Bound(p=>p.ProcessTime).Title("Process Time(ms)");
          columns.Bound(p=>p.DomainMessageCount);
          columns.Bound(p => p.FailureParseEventCount).Title("Items of Concern");
      })
                            .Sortable()
                            .Filterable(filterConfig => filterConfig
                                .Messages(messageConfig => messageConfig
                                    .Filter("Apply")
                                    .Info("Set Filter")))
      .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
      .DataSource(dataSource => dataSource
                                .Server()
                                .Model(model => model.Id(p => p.PackageId))
                          )

1 个答案:

答案 0 :(得分:1)

由于您可以使用多个行选择,因此可以使用select()方法,它将返回您选择的行数组。然后,您可以在按钮单击事件中访问下面的行值。

var packageGrid = $("#PackageGrid").data("kendoGrid");
var rows = packageGrid.select();
rows.each(function(index, row) {
  var selectedItem = packageGrid.dataItem(row);
  // var packageName= selectedItem.PackageName;
});

谢谢!

相关问题