asp.net-mvchtml-helperhtml.hiddenfor

Boolean with html helper Hidden and HiddenFor


What's up with this? The viewmodel variable is a bool with value true.

<%= Html.HiddenFor(m => m.TheBool) %>
<%= Html.Hidden("IsTimeExpanded",Model.TheBool) %>
<input type="hidden" value="<%=Model.TheBool%>" name="TheBool" id="TheBool">

Results in:

<input id="TheBool" name="TheBool" value="False" type="hidden">
<input id="TheBool" name="TheBool" value="False" type="hidden">
<input value="True" name="TheBool" id="TheBool" type="hidden">

What am I doing wrong? Why don't the helpers work as intended?


Solution

  • 1) use different (unique) ids

    2) don't use this helper, use

    <input type="hidden" name="the-name" 
      value="<%= Html.AttributeEncode(Model.TheBool) %>" id="TheBool_1216786" />