I am using FluentValidation and I have the following validation rule:
RuleFor(x => x.ClassId)
.NotNull()
.GreaterThan(0)
.WithMessage("Class is required field");
but when ClassId is null it shows its generic error message:
'Class Id' must not be empty
How to show the error message I specified inside the WithMessage() method?
Depending on Md Farid Uddin Kiron's comment I think for every rule we need to add WithMessage() as followings:
RuleFor(x => x.ClassId)
.NotNull()
.WithMessage("Class is required field")
.GreaterThan(0)
.WithMessage("Class is required field");