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?