The checkbox is not displaying in page. I tried many solutions in google. Nothing worked. Here s the code:
@model project.gamestatus
@using (Html.BeginForm("Create", "Calculator", FormMethod.Post, new { id = "frmID" }))
{
//other codes
<div class="form-group">
@Html.Label("Show on Screen", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.CheckBoxFor(m => m.display_status)
@Html.ValidationMessageFor(model => model.display_status, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-info" />
</div>
</div>
}
Only if the checkbox is shown in page i can proceed with validation. In my view there is no checkbox
First of all, you need to ensure that the display_status model is of boolean type and assigned the display name to it along with any validation.
[Display(Name="CheckBox Display Name")]
[Required]
public bool display_status { get; set; }
Also, @Html.CheckBoxFor do not support the label of checkbox. Therefore, you can have the label of the checkbox using @Html.LabelFor as follow:
<div class="form-group">
@Html.Label("Show on Screen", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.CheckBoxFor(m => m.display_status)
@Html.LabelFor(m => m.display_status)
@Html.ValidationMessageFor(m => m.display_status, "", new { @class = "text-danger" })
</div>
</div>
though its a very old post but I undergo this issue todat, but when I inspected I found that the CSS property opacity was set to 0 so changing it to 1 will solve the issue
@Html.EditorFor(model => model.Active, new { htmlAttributes = new { style = "opacity: 1" } })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With