I have this model:
public class SearchModel
{
[DefaultValue(true)]
public bool IsMale { get; set; }
[DefaultValue(true)]
public bool IsFemale { get; set; }
}
But based on my research and answers here, DefaultValueAttribute does not actually set a default value. But those answers were from 2008, Is there an attribute or a better way than using a private field to set these values to true when passed to the view?
Heres the view anyways:
@using (Html.BeginForm("Search", "Users", FormMethod.Get))
{
<div>
@Html.LabelFor(m => Model.IsMale)
@Html.CheckBoxFor(m => Model.IsMale)
<input type="submit" value="search"/>
</div>
}