I need to check a checkbox by default:
I tried all of these, nothing is checking my checkbox -
@Html.CheckBoxFor(m => m.AllowRating, new { @value = "true" })
@Html.CheckBoxFor(m => m.AllowRating, new { @checked = "true" })
@Html.CheckBoxFor(m => m.AllowRating, new { @checked = true })
@Html.CheckBoxFor(m => m.AllowRating, new { @checked = "checked"})
You should set the
AllowRating
property totrue
, preferably in the controller or model.Like other inputs, the checkbox's state reflects the value of the property.
You can do this with
@Html.CheckBoxFor()
:or you can also do this with a simple
@Html.CheckBox()
: