I have several checkboxes on a form. Only one of them is checked when it needs to be; all the others are unchecked regardless of whether the isChecked parameter is passed in as either true or false.
The checkboxes are coded like this:
<%= Html.CheckBox("cbName",Model.checkvalue)%>
<%= Html.CheckBox("cbName1",Model.checkvalue1)%>
I have stepped through the code and Model.checkValue and Model.checkValue1 are both true, but cbName is not checked and cbName1 is checked (in fact, in my actual app’ there are several more CheckBoxes and none are checked -except the second one in the form- although the Model properties are all true in the test I ran).
Has anyone come across this (mis)behavior before & can you let me know where I am going wrong, please? I can’t find a similar question anywhere, so I am hoping I am just making a simple error that will be quick to fix…
It was because the underlying data uses a nullable boolean.
I switched the
CheckBoxto aCheckBoxForand got the error outlined in this question and this told me that the problem is the fact that the underlying data currently uses a nullable boolean. Since this data type will be switched for a not null boolean once ready I don’t need to work around this.I hope this answer helps someone else.
Thank you for everyone’s contributions.