Custom validation attribute that compares the value of my property with another property’s value in my model class

Here’s how you could obtain the other property value: public class CustomAttribute : ValidationAttribute { private readonly string _other; public CustomAttribute(string other) { _other = other; } protected override ValidationResult IsValid(object value, ValidationContext validationContext) { var property = validationContext.ObjectType.GetProperty(_other); if (property == null) { return new ValidationResult( string.Format(“Unknown property: {0}”, _other) ); } var otherValue … Read more