0

I´m using fluent validation with the following rules:

public class MovieViewModelValidator : AbstractValidator<MovieViewModel>
{
    public MovieViewModelValidator()
    {
        RuleFor(m => m.Movie.Name).NotEmpty().WithMessage("Der Titel darf nicht Leer sein.")
                                .Length(0, 255).WithMessage("Der Titel darf nicht mehr als 255 Zeichen haben.");

        RuleFor(m => m.Movie.Description).NotEmpty().WithMessage("Die Beschreibung darf nicht Leer sein.")
                                .Length(0, 2000).WithMessage("Die Beschreibung darf nicht mehr als 2000 Zeichen haben.");

        RuleFor(m => m.Movie.ReleaseDate).NotEmpty().WithMessage("Das Erscheinungsdatum darf nicht Leer sein.");

        RuleFor(m => m.Movie.Duration).NotEmpty().WithMessage("Die Dauer darf nicht Leer sein.")
                                .LessThan(600).WithMessage("Die Dauer kann nicht über 600 Minuten betragen");

        RuleFor(m => m.Movie.AgeRestrictionId).NotEmpty().WithMessage("Bitte eine Altersbeschränkung wählen");
    }
}

The Problem is that if my Duration, ReleaseDate and AgeRestrictionId are empty the validation error message is "A value is required." and not the message I set in the rule. I tried already Empty(), Equal(0), NotEqual(0) and a lot of other things but I don´t understand why it´s not working. Can somebody help my and also give me an explanation why Empty() or NotEmpty() is not working when it works for the Name and the Description?

Alon
  • 687
  • 1
  • 6
  • 10
  • Why not use Data Annotation and override the behavior like this https://stackoverflow.com/a/53042280/2946329 – Salah Akbari Nov 02 '18 at 09:27
  • I would like to do it without Data Annotations and I would like to know where I misunderstood fluent validation. If you say there is no possibility to do it than I could use Data Annotations but I have a hard time to imagine there is no solution in fluent validation. – Kevin Kurz Nov 02 '18 at 14:57

0 Answers0