0

I have a class with multiple bool properties that must have at least 1 of that properties to be true, here is my class

public class Role : IValidatableObject {
   public int Id {get; set;}

   [Required(ErrorMessage = "Please enter a role name")]
   public string Name {get; set;}

   public bool IsCreator {get; set;}

   public bool IsEditor {get; set;}

   public bool IsPublisher {get; set;}

   public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
       if (!this.IsCreator && !this.IsEditor && !this.IsPublisher)) {
           yield return new ValidationResult("You must be a creator, editor or publisher");
       }
   }
}

i have ask this question for server side ModelState validation in this link, and now i need to do this on client side before my form doing postback..

Community
  • 1
  • 1
Dion Dirza
  • 2,575
  • 2
  • 17
  • 21
  • So what is your problem exactly? Do you already have a form? – A1rPun Nov 18 '14 at 07:55
  • yes, i have.. i want to trigger validate method like in code sample above on client side.. check my updated sample class – Dion Dirza Nov 18 '14 at 08:03
  • Your `ValidationAttribute` needs to implement `IClientValidatable`. [Refer this example](http://www.devtrends.co.uk/blog/the-complete-guide-to-validation-in-asp.net-mvc-3-part-2) –  Nov 18 '14 at 08:10
  • So this is gonna be complex code.. ok i see if i can accomplish this new attribute.. – Dion Dirza Nov 18 '14 at 08:20

0 Answers0