在主视图中选中部分视图中的复选框

时间:2018-07-26 07:35:31

标签: javascript c# asp.net-mvc checkbox partial-views

有关复选框的许多问题,但在此问题上没有帮助。我想在我的PartialView中选中我的复选框 FROM 我的MainView。

请在MainView上查看我的Ajax函数

$.ajax({
                url: '@Url.Action("Show", "Moderator")',
                data: { search: v, productName: p }

            }).done(function(data) {
                CloseWaitDialogue();
                $('#gridContent').html(data);
                $res = $(data).filter('#qFilterGrid'); //Finding this ID in my Partial View

                if ($res) {

                    $("#qFilterGrid th").each(function() {

                        if ($.trim($(this).text().toString().toLowerCase()) === "{checkall}") {
                            $(this).text('');
                            $("<input/>",
                                {
                                    type: "checkbox",
                                    id: "cbSelectAll1",
                                    value: "",
                                    class: "selectall",
                                    onclick: "SelectCheckBox(this);"
                                }).appendTo($(this));
                            $(this).append("<span>EnableALL</span>");
                        }

                    });
                }

            }).fail(function() {
                alert("FAIL");
            });

这是我的部分观点:

grid.Columns(
                grid.Column("Sl.No", format: @<text>
                                                 <div>
                                                     <span class="sl-holder">@( item.WebGrid.Rows.IndexOf(item) + 1)</span> <input type="hidden" value="@item.Id" class="p-id"/>
                                                 </div> </text>, canSort: false),
                grid.Column(
                    format: @<text>
                                @if (@item.EnableQueue)
                                {
                                    <text> <input id=@( item.WebGrid.Rows.IndexOf(item) + 1) type="checkbox" value="@item.EnableQueue" checked disabled="disabled" name="ids" class="disabled-true"/></text>
                                }
                                else
                                {
                                    <text><input id=@( item.WebGrid.Rows.IndexOf(item) + 1) type="checkbox" value="@item.EnableQueue" name="ids" class="dis"/></text>
                                }
                             </text>,
                    header: "{checkall}", style: "width"
                    ),
                grid.Column("Project", format: @<text> <span class="display-mode">@item.Project </span> </text>),
                grid.Column("Version", format: @<text> <span class="display-mode">@item.Version</span></text>),
                grid.Column("Mode", format: @<text><span class="display-mode lblMode">@item.Mode</span><label class="edit-mode lblMode"></label></text>, canSort: false),
                grid.Column("Priority", "Priority", format: @<text>
                                                                <span class="display-mode">
                                                                    <label class="lblPriority">@item.Priority</label>
                                                                </span> </text>, canSort: false))

如您所见,我希望从主视图中选中局部视图中的复选框。

我的某些尝试无效。

尝试1

$("#cbSelectAll1").on("click", function () {

        debugger;
        var ischecked = this.checked;
        $('#qFilterGrid tr').each(function () {

            if ($(this)[0].style.cssText === "display: table-row;" || $(this)[0].style.cssText == "") {
                $(this).find("input:checkbox").each(function () {
                    if (this.disabled != true) {
                        this.checked = ischecked;
                    }


                });
            }

        });


    });

尝试2

function SelectCheckBox(obj) {

        var c = new Array();
        c = document.getElementsByTagName('input');
        for (var i = 0; i < c.length; i++) {
            if (c[i].type == 'checkbox') {
                c[i].checked = obj.checked;
            }
        }
    }

我尝试了更多,但没有帮助。

我应该在SelectCheckBox();函数中写些什么?谢谢。

0 个答案:

没有答案
相关问题