Checkbox not working in mvc3

I have dynamic check box in my view. But its not working fine its always getting checked here is my code:

<input type="checkbox" onclick = "InActiveUser('@item.UserId')" id = "@item.UserId"   checked="@(item.IsActive == false ? false : true)" />

Please help thanks.


Checked attribute doesn't take true or false as a value. The sole presence of this attribute makes it checked. You have to remove this attribute if you want element to remain unchecked.

Read more in this answer


你必须这样做:

<input type="checkbox" onclick = "InActiveUser('@item.UserId')" 
 id = "@item.UserId" checked="@item.IsActive" />

As Patryk said - you need to change the way the checked attribute is added. Something like this:

<input type="checkbox" onclick = "InActiveUser('@item.UserId')" id = "@item.UserId"   @(item.IsActive ? "checked" : "") />

Try that.

链接地址: http://www.djcxy.com/p/56052.html

上一篇: Html表单单选按钮设置为默认基于PHP变量进行检查

下一篇: 复选框在mvc3中不起作用