Hi,
I have fluent validation configured like this.
I am trying to use validation selectively with this.
How do I stop the data annotation errors. I am confident that fluent validation is being called, because the custom messages show up. They are there in addition to the required field attributes being validated. Is there a way of clearing all the data annotation errors before fluent supplies it's own errors. That way I can use one or the other, and not both together.
Removing the attributes is a problem for me. They are generated, and are there for a reason.
I know this is a bit of a hybrid solution. The data annotations work just fine for the simple case, and I am happy for them to be there, just not when I have built a specific fluent validator.
I am using MVC4 and the latest (nuget) release of everything.
Thanks.
I have fluent validation configured like this.
FluentValidationModelValidatorProvider.Configure(
_ =>
{
// This does not seem to work, or i am misunderstanding it?
_.AddImplicitRequiredValidator = false;
});
I have a model that contains two objects Person and Organisation.I am trying to use validation selectively with this.
public class PartyModelValidator : AbstractValidator<PartyModel>
{
/// <summary>
/// Initialises a new instance of the <see cref="PartyModelValidator"/> class.
/// </summary>
public PartyModelValidator()
{
this.RuleFor(_ => _.Client)
.SetValidator(new ClientValidator())
.When(_ => _.SelectedPartyTab == PartyType.Person);
this.RuleFor(_ => _.Organisation)
.SetValidator(new OrganisationValidator())
.When(_ => _.SelectedPartyTab == PartyType.Organisation);
When the organisation is null, the required data annotation attributes result in validation errors. When the person is null, the required data annotation attributes result in validation errors.How do I stop the data annotation errors. I am confident that fluent validation is being called, because the custom messages show up. They are there in addition to the required field attributes being validated. Is there a way of clearing all the data annotation errors before fluent supplies it's own errors. That way I can use one or the other, and not both together.
Removing the attributes is a problem for me. They are generated, and are there for a reason.
I know this is a bit of a hybrid solution. The data annotations work just fine for the simple case, and I am happy for them to be there, just not when I have built a specific fluent validator.
I am using MVC4 and the latest (nuget) release of everything.
Thanks.