Asp.Net Mvc Checkboxfor default?

model

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

      

View

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

      

html output and this is my expected

<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">

      

but the checkbox is not checked. I can't figure out why? What am I missing?

Thank.

+3


source to share


1 answer


On MSDN



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

+2


source







All Articles