I have the following code in my view model which is working correctly and puts a validation message on my view:
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
yield return new ValidationResult("Required", new[] { "Insured.FirstName" });
}
However, I would like to reference the member name without using a string literal so I tried changing it to the following:
yield return new ValidationResult("Required", new[] { nameof(Insured.FirstName) });
This does not work. The validation message does not appear on my view. Is this not supported or am I doing this incorrectly?