Skip to content

Instantly share code, notes, and snippets.

@dontpaniclabsgists
Last active October 25, 2017 14:03
Show Gist options
  • Save dontpaniclabsgists/68ebb9b29498ab67a2a1a27845600cc3 to your computer and use it in GitHub Desktop.
Save dontpaniclabsgists/68ebb9b29498ab67a2a1a27845600cc3 to your computer and use it in GitHub Desktop.
validating_fields_mvc_2
public class MyModel : IValidatableObject
{
[Key]
public int Id { get; set; }
public int Item1 { get; set; }
public int Item2 { get; set; }
public int Item3 { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (Item3 < Item1 + Item2)
{
yield return new ValidationResult("Item1 + Item2 must be less than Item3", new List<string> { "Item3" });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment