网上看的清一色是这样的答案:
@Html.CheckBoxFor(m=>m.AddCustomer,new { @checked=true})
但实际是你这样写这个复选框根本未被选中。经过实验,这个是可以解决的。
首先要在controller中的相应action 中设置:
model.AddCustomer = true;
return View(model);
这个model的定义,我这里就不写了。你写好model中的各种默认值后,需要用 return View(model) 传到前端 cshtml 中才能使用。并且 AddCustomer 是bool 值,其他类型还不成。
前端cshtml 页面中的使用:
@Html.CheckBoxFor(m=>m.AddCustomer)
这样才可以真的使复选框默认为选中状态