@Html.DropDownList(
"CreatedByUser_ID",
new SelectList(
Model.GetUsers(),
"ID",
"Name",
(int)Model.CreatedByUser_ID),
"select one user----")
CreatedByUser_ID property on model has no Required attribute, but on client side the generated select box is validated. If I remove optionLabel (select one user—-) then validation is turned off.
Why mvc3 automatically validate my dropdownbox without required field ?
Thank you
I guess if your model property
CreatedByUser_IDis an int, the HTML rendered by the helper will not specify avalueattribute for the “select one user” option. You can’t give an int a null value, so the validation kicks in.Surely you would want the user to select an option? If not, try making your
CreatedByUser_IDa nullable int –int?in C#.