I am currently using javascript to generate HTML for checkboxes however when I go to post the form to my controller which accepts FormCollection as a parameter.
I then put these values into a dictionary and inspect the value within my dictionary. While other checkboxes only return one value, my autoDiscovery checkbox returns two which are 'on' and 'true', which doesn't make sense to me.
Here is the rendered HTML
<div class="form-group">
<div class="col-md-10">
<label class="col-md-3 control-label" for="autoDiscovery">
<input id="autoDiscovery" type="checkbox" checked="" data-val="false" name="autoDiscovery">
<input type="hidden" name="autoDiscovery" value="true"> Auto Discovery
</label>
</div>
</div>
and here is the javascript I am using to assign the checkboxes
function AssignCheckbox(variableName, jsonData, caption) {
var checked = jsonData == 1 ? 'checked' : '';
var value = jsonData == 1 ? 'true' : 'false';
return divFormGroupOpening + divOpeningInput +
'<label class="col-md-3 control-label" for="' + variableName + '">' + '<input id="' + variableName + '" type="checkbox" name="' + variableName + '" data-val="false"' + checked + '>' +
'<input type="hidden" value="' + value + '" name="' + variableName + '">' +
' ' + caption +'</label></div></div>';
}
checkedattribute.value="True"and the hidden input needs to bevalue="False"