MVC贡献网格带有复选框
-
28-09-2019 - |
题
我正在寻找如何在标题上添加复选框的方式,以支持检查或未选中我的Girdview的所有复选框。
<table class="grid">
<th><input type="checkbox" name="chkall"/></th>
<th>Name</th>
<tr>
<td>
<input type="checkbox" id="chkItem_1"/>
</td>
<td>
Category 1
</td>
</tr>
<tr>
<td>
<input type="checkbox" id="chkItem_2"/>
</td>
<td>
Category 2
</td>
</tr>
</table>
解决方案
column.For(x => Html.CheckBox("mycheckbox", new { @class = "foo" }))
.DoNotEncode()
.Header("<th><input type=\"checkbox\" id="chkHeader" /></th>");
然后,您可以使用jQuery处理标题复选框的更改事件,然后检查/取消选中所有选中:
$(function() {
$('#chkHeader').change(function() {
if ($(this).is(':checked')) {
$('.foo').attr('checked', 'checked');
} else {
$('.foo').removeAttr('checked');
}
});
});
其他提示
以下对我有用:
column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published');
不隶属于 StackOverflow