Код: Выделить всё
RuleFor(u => u.Id)
.Cascade(CascadeMode.StopOnFirstFailure)
.NotEmpty().WithMessage("Id is required")
.Must(ValidateId);
Код: Выделить всё
private bool ValidateId(CreateAccountBindingModel model, string id, PropertyValidatorContext context)
{
if (id=="test")
{
context.Rule.CurrentValidator.ErrorCodeSource = new StaticStringSource("You are testing");
return false;
}
var idValid = IdValidator.IsValid(id);
if (!idValid)
{
context.Rule.CurrentValidator.ErrorCodeSource = new StaticStringSource("Id is invalid");
return false;
}
return true;
}
Я пробовал установить они используют:
Код: Выделить всё
context.Rule.CurrentValidator.ErrorCodeSource = new StaticStringSource("Id is invalid");
Как определить сообщение об ошибке внутри функции проверки?
Подробнее здесь: https://stackoverflow.com/questions/384 ... t-function
Мобильная версия