【问题标题】:Get Checked Rows[Selected Rows] from kendo Grid从剑道网格中获取选中的行[选定的行]
【发布时间】:2014-11-06 12:04:21
【问题描述】:

Here is My grid, When Checkbox is Selected I want to pass the CheckBox Checked/Not Checked Value to Controller.在控制器模型中访问时不会保留 Checkbox 值。你能指导我实现它吗?

我的观点:

@using(@Html.BeginForm("RequisitionApply", "Requisition", FormMethod.Post, new               {           approvalReason = Model, @id = "addExpenseItem" }))
{
    @(Html.Kendo().Grid<ZCW.MVC.ViewModels.ManagerRequisitionSearchListViewModel>()
                 .Name("ManagerRequisitionApprovalGrid")
                  .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Events(e => e.RequestEnd("GetPaginationDisplay"))
                                    .PageSize(25)
                                                    .Read(read => read.Action("GetDetails", "List").Type(HttpVerbs.Get))
                      //.Update(update => update.Action("Apply", "List").Type(HttpVerbs.Post))
                                    .ServerOperation(true)
                                    )
                             .Columns(columns =>
                        {
                            //RequistionName(ID)
                            columns.Bound(p => p.FirstName).ClientTemplate("#=FirstName#<a href='" + Url.Action("GetResource", "List", new { NameID = "#=NameID#"}) + "'>(#=NameID#) </a>").Title(@Html.LocalizedText("ID")).HtmlAttributes(new { @class = "alignleft" });

                            //Location
                            columns.Bound(p => p.Location)
                                    .Title(@Html.LocalizedText("Location")).HtmlAttributes(new { @class = "alignleft" });


                            // Accept Header
                              columns.Template(p => p.Accept).Title("")
                                .HeaderTemplate("<i class='icon-ok gicn tooltips' data-original-title='Approve' data-placement='top'></i><br><div class='checker'><span><input id='selectallApprove' class='chkboxApprove' type='checkbox' onclick='ToggleChkBoxApprove(this.checked);' #= Accept ?  checked='checked' : '' # /></span></div>")
                                 .ClientTemplate("<span>  <input id='checkbox' onclick='grdChkBoxClick(this); ' class='chkboxApprove' type='checkbox' name='remember' /></span>")
                                   .HeaderHtmlAttributes(new { @class = "aligncenter" })
                                .HtmlAttributes(new { @class = "textaligncenter" });


                            //Decline Header
                            columns.Template(p => p.Decline).Title("")
                               .HeaderTemplate("<i class='icon-remove ricn tooltips' data-original-title='Decline' data-placement='top'></i><br><div class='checker'><span> <input id='selectallDecline'   class='chkboxDecline' type='checkbox' onclick='ToggleChkBoxDecline(this.checked);' #= Decline ?  checked='checked' : '' # /></span></div>")
                                .ClientTemplate("<span>  <input id='checkbox1' onclick='grdChkBoxClick(this); ' class='chkboxDecline' type='checkbox' name='remember'/></span>")
                                  .HeaderHtmlAttributes(new { @class = "aligncenter" })
                               .HtmlAttributes(new { @class = "textaligncenter" });
                        })
                                                                             .AutoBind(true)
                                                                                    .Sortable()
                                                                                    .EnableCustomBinding(true)
                    )

     <div class="pull-right">
                            <button type="submit" id="Apply" class="submitbtn" style="border: 0px none;"><i class="greenbtn"></i>@GlobalResourceHelper.GetGlobalResource(ResourceFiles.ButtonsResources, "BTN_APPLY")</button>
                        </div>
}

我的控制器:

 public ActionResult Apply(ResourceViewModel ApprovalList)
 {
     // I'm not getting Checkbox Checked or not in ApprovalList
  }

【问题讨论】:

  • 您的复选框甚至没有名称属性,因此它们不会回发(以及由于重复的 id 而导致的无效 html)
  • @Stephen 我已经更改了 ID 并添加了一个名称属性,然后值也没有保留,我已经编辑了我的代码
  • 你是通过 ajax 发帖吗?
  • 您的 html 仍然无效(每一行都有一个带有 id=checkbox 的复选框)所以摆脱 id 的。现在您有很多带有name="remember" 的复选框,它们与ResourceViewModel 无关(您可以检查Request.Form 以查看发回的内容)但是由于未选中的复选框不会发回,因此无法匹配哪个行是否已“检查”。
  • @Ankush :不,我没有使用 Ajax

标签: asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 kendo-ui kendo-grid


【解决方案1】:

你必须这样做。

columns.Bound(x => x.IsChecked).ClientTemplate(
"<input name='IsChecked' class='chkBox' type='checkbox' 
  data-bind='checked: IsChecked' #= IsChecked ? checked='checked' : '' #/>");

        //check document ready 
    var grid = $("#Grid").data("kendoGrid");
        grid.tbody.on("change", ".chkBox", function (e) {

            var row = $(e.target).closest("tr");
            var item = grid.dataItem(row);                
            //item.set("IsChecked", $(e.target).is(":checked") ? 1 : 0);
            kendo.bind(this,item);//this line or above line will handle this
        });   

使用 ajax 调用发布 Grid 并发送 Grid 的数据。

   var gridData = $("#Grid").data("kendoGrid");
       //AJAX etc...
        data: JSON.stringify(gridData.dataSource.view()),

【讨论】:

    猜你喜欢
    • 2018-11-01
    • 2014-01-29
    • 1970-01-01
    • 1970-01-01
    • 2023-03-23
    • 2015-08-12
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多