【问题标题】:Get Kendo grid multi select items to MVC controller将 Kendo 网格多选项目获取到 MVC 控制器
【发布时间】:2015-08-18 18:07:37
【问题描述】:

我有一个带有多选复选框的 Kendo Grid。(一一选择或全选)。当我单击全选或一一选择时,我需要获取所选行的 ID。

在我的程序中,多项选择是可以的。但我不知道如何将选定的 Id 获取到 MVC 控制器端。

我想获取 MVC 控制器的 Selected NewsId 列表

我的剑道网格

@model TVT.Regional.Web.Models.ViewModel<NEWS.Current.NewsModel>
 @(Html.Kendo().Grid<NEWS.Current.NewsModel>()
  .Name("NewsGrid")
  .Columns(columns =>
  {
      columns.Bound(x => x.NewsID).Template(@<text></text>).ClientTemplate("<input type='checkbox' class='chkbox' />");
      columns.Template(c => { }).ClientTemplate("<input type='checkbox' id='${NewsID}'  class='chknewsdtl' value='${NewsID}'/>");
      columns.Bound(x=>x.NewsId).Width(80).Title("News Id");
  })

 .Scrollable()
  .Sortable()
  .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
  .Filterable()
  .Events(events => { events.Change("onRowSelected"); })
  .Pageable(pageable => pageable
  .Refresh(true)
  .PageSizes(true)
  .ButtonCount(5))
  .DataSource(datasource => datasource.Ajax().Read(read => read.Action("GetAllRegionalNews", "NewsController")))
    )

我已经通过 Javascript 执行复选框多选。我有一个按钮和按钮单击触发器 MVC 控制器。

我的 MVC 控制器

 public ActionResult RegionalNewsCon(NewsModel mod) // In here i take a NewsModel object,i have no idea is that correct when i get a list of NewsId's
    {
       // Some code here
    }

我的模特

public class NewsModel
    {
        public int NewsId { get; set; }
        public string NewsName { get; set; }
        //other properties here
    }

【问题讨论】:

    标签: c# jquery asp.net-mvc kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    探索在您的 Kendo Grid 中添加 AJAX 更新调用:

    .Datasource(datasource => datasource.Ajax
        .Read(read => read.Action(...))
        .Update(update => update.Update("UpdateAction", "Controller"))
    

    然后在你的控制器中添加一个动作:

    public ActionResult UpdateAction(IEnumerable<NewsModel> model)
    {
        //...do stuff
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-11
      • 2021-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多