Mvc Contrib grid with checkbox

后端 未结 2 1798
逝去的感伤
逝去的感伤 2021-01-16 07:39

I\'m looking for the way how to add a checkbox on the header that support checked or unchecked all my checkbox column of my girdview.

    
相关标签:
2条回答
  • 2021-01-16 08:23

    The following has worked for me :

    column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published');
    
    0 讨论(0)
  • 2021-01-16 08:39
    column.For(x => Html.CheckBox("mycheckbox", new { @class = "foo" }))
        .DoNotEncode()
        .Header("<th><input type=\"checkbox\" id="chkHeader" /></th>");
    

    And then you could use jquery to handle the change event of the header checkbox and check/uncheck all the others:

    $(function() {
        $('#chkHeader').change(function() {
            if ($(this).is(':checked')) {
                $('.foo').attr('checked', 'checked');
            } else {
                $('.foo').removeAttr('checked');
            }
        });
    });
    
    0 讨论(0)
提交回复
热议问题