I’ve tried both CheckboxFor and EditorFor to bind a checkbox to the model.
The issue is that it’s always unchecked and it does not seem to reflect the true/false value from the model.
View
@Html.CheckBoxFor(x => x.IsConfirmed)
Result in browser
<input name="IsConfirmed" id="IsConfirmed" type="checkbox" value="true"/>
<input name="IsConfirmed" type="hidden" value="false"/>
View
@Html.EditorFor(x => x.IsConfirmed)
Result in browser
<input name="IsConfirmed" class="check-box" id="IsConfirmed" type="checkbox" data-val="true" value="true"/>
<input name="IsConfirmed" type="hidden" value="false"/>
What am I missing?
As @musefan commented, the issue is with my view and not the HtmlHelper.
The issue boiled down to “chain-of-events”. The view was binded post-load by ajax, and the value for the checkbox was not set up for this call.