Validating only selected fields using ASP.NET MVC 2 and Data Annotations
- by thinknow
I'm using Data Annotations with ASP.NET MVC 2 as demonstrated in this post:
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
Everything works fine when creating / updating an entity where all required property values are specified in the form and valid.
However, what if I only want to update some of the fields? For example, let's say I have an Account entity with 20 fields, but I only want to update Username and Password?
ModelState.IsValid validates against all the properties, regardless of whether they are referenced in the submitted form.
How can I get it to validate only the fields that are referenced in the form?