Wednesday, September 24, 2014

ASP.NET MVC Razor Unrequired property keeps getting data-val-required attribute

If you have the problem that your text field validation gets generated althoug there is no Required attribute set on property, use the next code in the Application_Start to force the compiler to validate only if there is a required attribute on the property:

// Whit this line of code you will remove data-val-required DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

// With these two lines you will remove data-val-number and data-val ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new DataAnnotationsModelValidatorProvider());


No comments:

Post a Comment