JimmiTh's comment on the question provided a key insight for me to resolve this for myself.
In my case, I definitely did add an additional provider to ModelValidatorProviders
. I added a custom validation factory (using Fluent Validation) with this code in my Global.asax.cs file:
ModelValidatorProviders.Providers.Add(
new FluentValidationModelValidatorProvider(validatorFactory));
But using multiple providers isn't necessarily problematic. What seems to be problematic is if multiple providers provide the same validators, because that will register the same rules multiple times, causing the mentioned problem with the Microsoft unobtrusive validation code.
I ended up removing the following line from the same file as I decided I didn't need to use both providers:
FluentValidationModelValidatorProvider.Configure();
The Configure
method above is itself adding a provider to ModelValidatorProviders
, and I was effectively registering the same validator class twice, hence the error about non-unique "validation type names".
The SO question jquery - Fluent Validations. Error: Validation type names in unobtrusive client validation rules must be unique points to another way that using multiple providers can lead to the mentioned problem. Each provider can be configured to add an 'implicit required attribute to 'value types' (i.e. view model properties that aren't nullable). To resolve this particular issue, I could change my code to the following so that none of the providers add implicit required attributes:
FluentValidationModelValidatorProvider.Configure(
provider => provider.AddImplicitRequiredValidator = false);
DependencyResolverValidatorFactory validatorFactory =
new DependencyResolverValidatorFactory();
FluentValidationModelValidatorProvider validatorFactoryProvider =
new FluentValidationModelValidatorProvider(validatorFactory);
validatorFactoryProvider.AddImplicitRequiredValidator = false;
ModelValidatorProviders.Providers.Add(validatorFactoryProvider);
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
<add key="ClientValidationEnabled" value="true"/>
and<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
from theappSettings
in the rootWeb.config
fixed the problem. – PhilologianWeb.config
which points to another config file,\Configuration\[Region]\AppSettings.config
. I removed the aforementioned settings from this file. They do, however still exist in the\Views\Web.config
file. However, it does appear that JS validation is not currently working. Which I DO want to work so I guess I have some more digging to do! – PhilologianModelValidatorProviders.Providers
?HTMLHelper
(which is what throws this error) only gets unobtrusive validation rules by consulting those providers, and ifDataAnnotationExtensions
isn't causing it (and we'll assume the defaultDataAnnotationModelValidatorProvider
isn't causing it by itself either), there should be another provider inthere, for this error to occur. – Bookrack