I have a guest book form created using asp.net mvc.
The valid gender
form field must be filled in by selecting a value from a drop down control. The drop down control has 3 options, i.e., "--Select--", "Female", "Male" and the "--Select--" is selected by default. The data model has been setup to force the visitor select either female or male but not "--Select--".
We know that the visitor has a chance to temper the form data, so he can submit the gender
form field pointing to a value that does not exist in the database.
My question is:
- Can DataAnnotation prevent the user from posting a form field that does not exist in a database?
- What is the preferred approach to counter this attempt? Do I have to check the submitted gender form field first before invoking
SaveChanges()
?