Mvc Contrib grid with checkbox

可紊 提交于 2019-12-01 13:08:22
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');
        }
    });
});
Eric Amerson

The following has worked for me :

column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!