I have a property called Campus2Id that being rendered as a dropdown using the built-in HtmlHelper in Razor. By default, unobstrusive and jquery validate is enabled.
When I do a form submit, somehow the ModelState shows that there is an error for that property; however, I did not add any validation attribute like Required to that property.
Is there a reason why Mvc marks this property having a validation error?
Model
[Display(Name = "Campus")]
public Int32 Campus2Id { get; set; }
View
<div class="form-group">
@Html.LabelFor(model => model.Campus2Id, new { @class = "sr-only" })
@Html.DropDownListFor(model => model.Campus2Id, new SelectList(Model.Campuses, "Id", "ShortName"), Model.CampusesLabel, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Campus2Id)
</div>
The error seems to be that the required validation is getting triggered on the Campus2Id field even though I did not specify [Required] attribute.
