javascript - 如何获取选中复选框的值(在jqgrid的页脚中)并发送到 Controller ?

标签 javascript jquery asp.net-mvc-4 checkbox jqgrid

我在 jqgrid 的页脚中有复选框,并且希望在单击按钮(发送命令)时将复选框的值发送到 Controller 。 enter image description here

当选择一行并单击按钮发送命令时, 除了其值之外,还会发送复选框(选中或未选中) 我的代码:

 .jqGrid('navButtonAdd', '#pager',
                       {
                       caption: "Send Command ", buttonicon:"ui-  icon-signal-diag", title: "Send Command ",
                            onClickButton: function () {
                                var selRow =    jQuery("#list").jqGrid('getGridParam', 'selarrrow');  //get selected rows
                                var dataToSend = JSON.stringify(selRow);
                                if (selRow == 0) {
                                    // display error message because no row is selected
                                    $.jgrid.viewModal("#" + 'alertmod_' + this.p.id,
                                        { gbox: "#gbox_" +   $.jgrid.jqID(this.p.id), jqm: true });
                                    $("#jqg_alrt").focus();
                                }
                                else {
                                    $.ajax({
                                        url: '@Url.Action("Index", "AddSMS")',
                                        type: 'POST',
                                        contentType: 'application/json; charset=utf-8',
                                        data: dataToSend,
                                        dataType: 'json',
                                        success: function (result) {
                                            alert('success');
                                        }
                                    });
                                }
                            }
                        })
        $("#pager_left table.navtable tbody tr").append( // here 'pager' part or #pager_left is the id of the pager
'<td><div><input type="checkbox" class="myMultiSearch" id="WithSetting" />Setting </div></td>');

我可以发送行数据,但我不知道如何发送复选框的值???

最佳答案

您将其作为 URL 参数发送。变化:

url: '@Url.Action("Index", "AddSMS")',

url: '@Url.Action("Index", "AddSMS")' + '?cbChecked=' + $("input.myMultiSearch").is(":checked"),

然后您应该能够将 AddSMS Controller 中的 Index 更新为:

public ActionResult Index(long[] selrow, bool cbChecked) 
{ 
    if (cbChecked) 
    {
        //this should run if the checkbox has been checked
    }
//......

关于javascript - 如何获取选中复选框的值(在jqgrid的页脚中)并发送到 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29873913/

相关文章:

javascript - 将 JavaScript 函数分配给提交按钮,该函数应有条件地执行

javascript - 将表单状态保存到服务器而不干扰页面

javascript - iOS 忽略 Swiper 画廊的容器宽度

javascript - 从变更事件中获取旧值

c# - 如何在 mvc 4 razor 的数据库中保存嵌套的可排序菜单?

c# - RDLC 矩阵的行号

javascript - 如何在使用两个滚动条时将拖动的 div 置于所有内容的顶部?

jquery - 如何通过remoteFunction传递g:datePicker值?

javascript - 如何清除打开的弹出框中的元素

c# - 使用日期时间、小数、GUID 和 Nullable 类型时,MVC 模型绑定(bind)速度较慢