MVC 5 Razor view not binding bool to input

asp.net-mvc, asp.net-mvc-4, c#, html, razor

Solution

See this Answer

Basically you want to use `HTML.CheckBoxFor(model => model.booleanProperty)`

Problem

I have a razor view (Framework 4.5, MVC 5) and an html input type=checkbox with the value equal to a model boolean value but instead of true or false it binds "value". This is my code: ``` for (int index = 0; index < Model.Item1.Locations.Length; index++) { WSTupleOfInt32StringStringBoolean location = Model.Item1.Locations[index]; <div class="editor-field"> <input id="@string.Format("presentation.ServiceInfoes[{1}].Locations[{0}].Key", index, Model.Item2)" type="checkbox" value="@location.ThirdValue" name="@string.Format("presentation.ServiceInfoes[{1}].Locations[{0}].ThirdValue", index, Model.Item2)" /> </div> <div class="editor-label"> <label for="@string.Format("presentation.ServiceInfoes[{1}].Locations[{0}].Key", index, Model.Item2)">@location.FirstValue</label> @if (!string.IsNullOrEmpty(location.SecondValue)) { <a href="@string.Format("//maps.google.com/?q={0}", location.SecondValue)" target="_blank"><img alt="@location.SecondValue" src="@string.Format("//maps.google.com/maps/api/staticmap?center={0}&markers=color:blue|{0}&zoom=15&size=64x64&sensor=false", location.SecondValue)" /></a> } </div><br /> } ``` The `location.ThirdValue` is the boolean property, debuging the property it's fine.. but in the HTML i get `value="value"` and not `value="false"`. What's happening?

Original source

Related problems