Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

Commented Issue: FluentValidationModelValidatorProvider incompatible with MVC4 [7097]

$
0
0
In wanting to add in collection of FluentValidationModelValidatorProvider ModelValidatorProviders with MVC4, it generated an exception indicating that the type does not correponding to the type of the collection ModelValidatorProvider.

This is a mismatch error between reference of version MVC3/MVC4, workaround I use a decorator here is the code:

public class FluentValidationModelValidatorProvider : System.Web.Mvc.ModelValidatorProvider
{
private global::FluentValidation.Mvc.FluentValidationModelValidatorProvider m_InnerValidationProvider;

public FluentValidationModelValidatorProvider(global::FluentValidation.IValidatorFactory validatorFactory = null)
{
m_InnerValidationProvider = new global::FluentValidation.Mvc.FluentValidationModelValidatorProvider(validatorFactory);
}

public override IEnumerable<ModelValidator> GetValidators(System.Web.Mvc.ModelMetadata metadata, ControllerContext context)
{
return m_InnerValidationProvider.GetValidators(metadata, context);
}
}




Comments: The current FluentValidation.Mvc dll is only compatible with MVC3. I have a version that is compatible with MVC4 that I'll aim to push out in the next week or so. For now, you can build your own version of the dll by swapping out the reference to MVC3 with MVC4.

Viewing all articles
Browse latest Browse all 1917


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>