Last active
October 25, 2017 14:03
-
-
Save dontpaniclabsgists/68ebb9b29498ab67a2a1a27845600cc3 to your computer and use it in GitHub Desktop.
validating_fields_mvc_2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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