Reputation: 5379
I have an bool property in a class. And using <%= Html.EditorForModel() %>
its generating this code:
<div class="editor-field">
<input class="check-box" id="Ativo" name="Ativo" type="checkbox" value="true">
<input name="Ativo" type="hidden" value="false">
</div>
My question is: why it's creating an input hidden ?
Upvotes: 1
Views: 183
Reputation: 1857
It's because when you submit a form, unless the checkbox is checked, it will not be submitted to the server in the postback. it helps distinguish between a false value and a missing value. They are just working around one of the vagaries of the way forms work on the web.
Upvotes: 3