2

I have a property of type Datetime? that I want to validate with FluentValidation.

Here is the property :

public DateTime? StartContractDate { get; set; }

Here is my actual Validator who works very good with a good formated date :

RuleFor(x => x.StartContractDate).Cascade(CascadeMode.StopOnFirstFailure)
.NotNull().WithMessage(localizationService.GetLocaleStringResourceByName("Contract.Create.Create_Identification.Validate.StartContractDate").ResourceValue)
.Must(StartContractDateValidation).WithMessage(localizationService.GetLocaleStringResourceByName("Contract.Create.Create_Identification.Validate.StartContractDateValidation").ResourceValue);

I tried what I saw in that link Validate DateTime with FluentValidator without success, I go in the BeAValidDate function but in the navigator I still have the error "The value 'XXX' is not valid for 'StartContractDate' instead of my custom message that I put in WithMessage(...).

If you have any suggestion ?

1 Answers1

0

I found an answer to my question so I share it if it can help someone.

The error "The value 'XXX' is not valid for 'fieldName' is set before the FluentValidation and I didn't find a solution to handle it inside. So i searched where this message was setted and it was in a file named "MvcLocalization.resx". There was another file "MvcLocalization.de.resx" so I tried to add an "fr" version (it was my objective, to change and made that message translatable).

So the solution was to add the "MvcLocalization.fr.resx" file, add the sames keys with the good translation and it works very good.