@Html.CheckBoxFor is not rendering a hidden input when it renders the checkbox input.
Everything I have seen online indicates that the CheckBoxFor helper always renders 2 elements. Today... out of the blue... MVC/Razor STOPS rendering 2 inputs. I cannot figure out why.
Not much code:
@Html.CheckBoxFor(m => m.IsAgreed)
Renders:
<input checked="checked" data-val="true" data-val-required="The field is required." id="IsAgreed" name="IsAgreed" type="checkbox" value="true">
Normally it renders this:
<input checked="checked" data-val="true" data-val-required="The IsEnabled field is required." id="Program_IsEnabled" name="Program.IsEnabled" type="checkbox" value="true">
<input name="Program_IsEnabled" type="hidden" value="false">
It went through these items:
- There are no attribute decorations on the ViewModel that would effect the ModelState.
- The
IsAgreedis a bool.public bool IsAgreed { get; set; } - It is rendered in a partial, but moving the CheckBoxFor to the parent page does not change how it renders.
- There is no javascript effecting the element.
- I can add the
includeHiddenInput = true, but I have never had to do that on any other element in the 7 years I've been working with this software. - I am using .net 8 core instead of .net 5 framework, and looked up the differences between the InputExpensions and there doesn't seem to be much difference.
- I did not find anything online or with AI that would explain it. Apparently, the checkbox and hidden is .net's default way of rendering a CheckBoxFor, so why this is not, is a mystery.
If you've ran across this, any recommendations would be great! Thanks in advance.
Edit:
I think I might have found more regarding this. All the checkboxs that I am expecting to have the hidden field... I found the hidden fields. They are at the bottom of the form tag, not nested with the other checkbox input... why is that I wonder.