In my ASP.NET MVC4 model I have a required property:
[Required(ErrorMessage = "Select a class")]
public string ClassName { get; set; }
This is bound to a drop-down list in the Razor view:
@Html.DropDownListFor(o => o.ClassName, new SelectList(Model.ClassList))
@Html.ValidationMessageFor(model => model.ClassName)
However, I have set the first element of Model.ClassList as the placeholder string "Select one". If the user submits the form without choosing a class, it registers as valid because ClassName has a value of "Select one".
How can I make this placeholder selection invalid?
@Html.DropDownListFor(o => o.ClassName, new SelectList(Model.ClassList), "Select one")