How to set a CheckBox by default Checked in ASP.Net MVC
You could set your property in the model's constructor
public YourModel()
{
As = true;
}
@Html.CheckBox("yourId", true, new { value = Model.Ischecked })
This will certainly work
In your controller action rendering the view you could set the As
property of your model to true:
model.As = true;
return View(model);
and in your view simply:
@Html.CheckBoxFor(model => model.As);
Now since the As property of the model is set to true, the CheckBoxFor helper will generate a checked checkbox.
Old question, but another "pure razor" answer would be:
@Html.CheckBoxFor(model => model.As, htmlAttributes: new { @checked = true} )