asp.net-mvc – Asp.Net Mvc Checkbox为默认值?

模型

[DefaultValue(true)]
public bool IsActive { get; set; }

视图

@Html.CheckBoxFor(model => model.IsActive)

html输出,这是我的预期

<input data-val="true" data-val-required="Yayında alanı boş bırakılmamalıdır!" id="IsActive" name="IsActive" type="checkbox" value="true" class="valid">

但是没有选中复选框.我不明白为什么?我错过了什么?

谢谢.

最佳答案 每
MSDN

A DefaultValueAttribute will not cause a member to be automatically initialized with the attribute’s value. You must set the initial value in your code.

点赞