Problem with MVC2 RC?

Feb 19, 2010 at 3:13 PM

Hi,

I'm having a few issues getting this to work with MVC2 RC.   I decided to look at your example project to see where I was going wrong and found that similar behaviour is exhibited there.

When building the jQuery validators from the view model it hits the Age field first.  Although the Age field has 3 validator attributes in the model (Digits, Max and Min), the MetaData for Age is also specifying the MVC Required validator.

When it's looking through your validator dictionary it's not finding a validator for MVC's "required" and generating an error.

Is there any way of ignoring the standard MVC validators?

Thanks
Rob

 

Feb 26, 2010 at 10:24 AM

Update on this.

Jeremy Skinner has a blog post showing a workaround for this issue.   Out of the box MVC2 attaches a 'Required' attribute to any non-null field. 
There's a property on the validator provider which will switch this behaviour off.

DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

Make sure you're using MVC2 RC2, this property doesn't exist in RC1.

Following on from this I saw similar behaviour when the data model used numeric types, the MVC 'Numeric' validator was coming through from the meta data.

In the end I made a small change to the source code.  It will check to see if the ignore flag has been set and if it has, standard MVC validators will be ignored.