AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

Asp.Net Mvc Checkboxfor default value?

model

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

view

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

html output and that 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 checkbox is not checked. I cant understand why? What am I missing?

Thanks.

Upvotes: 4

Views: 4098

Answers (1)

cadrell0
cadrell0

Reputation: 17307

Per the 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.

Upvotes: 2

Related Questions