How can we make a checkbox checked or unchecked programatically based on the value? That is to say, for a particular user if the value is true, the checkbox should be checke
If you're using MVC and passing in model values correctly from your controller, then
@Html.CheckBoxFor(model => model.checkBox1)
...is all you need. The html-helper does the logic to figure out whether or not to insert the checked="checkbox"
code.
Otherwise, without the HTML-helper you can dynamically generate the attribute yourself (others have pointed out how), but don't make the mistake of thinking that checked = ""
will leave the box unchecked. See this answer for an explanation.