Validating only selected fields using ASP.NET MVC 2 and Data Annotations

Posted by thinknow on Stack Overflow See other posts from Stack Overflow or by thinknow
Published on 2010-03-22T17:56:54Z Indexed on 2010/03/22 18:01 UTC
Read the original article Hit count: 404

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about data