Reputation: 1187
In my view I have,
@Html.CheckBoxFor(m => m.IsExist, new { @id = "IsExist" })
In my Model I have IsExist value from DB. Either true or false.
Now how can I 'Check' or 'Uncheck' the option, based on the true or false value in IsExist. I expected, on binding by default the check box takes the value of Model. Howeverr that is not happening.
How can i achieve it?
Upvotes: 2
Views: 6894
Reputation: 395
Below snippet indicates an alternate way of having checkbox created and conditionally making it checked/unchecked. The following approach is also useful to get the value of checkbox by traditional approach using jquery.
@model myproject.Models.StudentModel
<div class="row">
<label class="checkbox-inline">
<input type="checkbox" name="selfStudy" checked="@Model.IsExist"><b>Self Study</b>
</label>
</div>
Upvotes: 3
Reputation: 31
Here how i achieved it
@Html.CheckBox("VC",(item.isVC=="Y") ? true : false)
where my item.isVC
has value "Y" or "N"
Upvotes: 3
Reputation: 6499
You can do this to check a checkbox :
if (Model.IsExist) {
@Html.CheckBoxFor(m => m.IsExist, new { @id = "IsExist", "checked" = "checked"})
}
Hope it's help
Upvotes: 2