2014-03-04 37 views
0

我正在使用asp.net MVC 3 Telerik Extension。我有一個應該被檢查或不檢查的telerik網格內的複選框。我注意到複選框的值正確,他們是真的或假的。但是,即使在checked =「False」時,複選框仍然會被檢查。Telerik Grid內部的CheckBox始終檢查值是否爲假值

下面

是一個示例代碼:

columns.Bound(o => o.currentStudent).Title("Current Student") 
    .Template(
    @<text> 
     <input type="checkbox" id="chkCurrentStudent" name="chkCurrentStudent" value="@item.currentStudent" checked="@item.currentStudent" /> 
    </text> 
) 

的HTML代碼,呈現在客戶端:

<input name="chkCurrentStudent" id="chkCurrentStudent" type="checkbox" checked="True" value="True"> 

缺少什麼我在這裏?

回答

0

讀一些答案後,我改變了代碼。以下是最新的代碼現在的樣子。

columns.Bound(o => o.currentStudent).Title("Current Student") 
    .Template(
    @<text> 
     <input type="checkbox" id="chkCurrentStudent" name="chkCurrentStudent" value="@item.currentStudent" @(item.currentStudent=="True" ? "checked=checked": "") /> 
    </text> 
) 
1

我相信,在HTML複選框正確的屬性是:

對於選中的複選框: 檢查=「檢查」

對於選中框,您只需忽略checked="checked"

由於您所傳遞checked="false",您的瀏覽器仍在解釋選中的複選框。它只是在解析HTML時查找屬性checked的存在。不要緊,什麼屬性的值是...

我添加了一個例子,在的jsfiddle:http://jsfiddle.net/pqz28/

希望幫助!

1

變化

columns.Bound(o => o.currentStudent).Title("Current Student") 
    .Template(
    @<text> 
     <input type="checkbox" id="chkCurrentStudent" name="chkCurrentStudent" value="@item.currentStudent" checked="@item.currentStudent" /> 
    </text> 
) 

columns.Bound(o => o.currentStudent).Title("Current Student") 
     .Template(
     @<text> 
      <input type="checkbox" id="chkCurrentStudent" name="chkCurrentStudent" value="@item.currentStudent" 
@(item.currentStudent ? Html.Raw(" checked=\"checked\"") : null) /> 
     </text> 
    )