2010-11-25 2 views
1

내 girdview의 모든 체크 박스 열을 체크하거나 체크하지 않은 헤더를 체크하는 방법을 찾고 있습니다.Mvc 체크 박스로 콘트 리뷰 게시

<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> 

답변

9
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'); 
     } 
    }); 
}); 
+2

DoNotEncode()가 사용되지 않습니다. 대신 Encode (false)를 사용하십시오. – Eldar

5

나를 위해 일했다 다음 :

column.For(x => Html.CheckBox('chkBox', x.Published)).Named('Published'); 
관련 문제