I wonder if someone could pass on some advice please.....
I have four checkboxes that are styled up in css. This is the straight HTML.
<div class="checkbox checkbox-danger">
<input id="showInDirectory" name="showInDirectory" type="checkbox" class="styled">
<label for="showInDirectory">
Show in directory?
</label>
</div>
and this is what is rendered on the page
And I'm trying to replicate this in 'code' so in my model I have
public bool showinDirectory { get; set; }
And I set the true/false value based on what's held in the db for this value.
So the in my view I've entered:
<div class="checkbox checkbox-danger">
@Html.CheckBoxFor(x => x.showInDirectory, new { id = Html.NameFor(x => x.showInDirectory) })
<label for="@Html.NameFor(x => x.showInDirectory)">Show in Directory</label>
</div>
Which when rendered gives:
The value is always false and it's unselectable. The actual HTML that is generated is:
<div class="checkbox checkbox-danger">
<input checked="checked" data-val="true" data-val-required="The showInDirectory field is required." id="showInDirectory" name="showInDirectory" type="checkbox" value="true">
<input name="showInDirectory" type="hidden" value="false">
<label for="showInDirectory">Show in Directory</label>
</div>
I think that it's something to do with the hidden input that's being created but I just can't work out how to fix.
Could someone give me some advise please?
thanks, Craig