in my MVC3 application, I've a form with 2 dropdownlists that aren't required. So, I haven't added any annotation to the related attributes on the partial class. Viewing the html code generated when I add a new object, no client validation code is added and all goes fine. The problem rises when I try to modify an object that has values on attributes related with the dropdownlists because automatically is added this code
data-val="true" data-val-number="The field IDCategory must be a number." data-val-required="The IDCategory field is required." id="ddlCategory" name="List.Category.IDCategory"
So, if on this object I try to set no value on the dropdownlists and after submit the form, it is fired the validation error. I think that the solution are 2:
- Add some annotation on the related attribute to always avoid the generation of validation code
- Add an attribute to the object in the view (like the cancel class on the buttons, I tried to add to them, but it doesn't works)
Thanks in advance!