title: IValidatableObject not working in mvc 4 web app
body: <p>So I have web app that is registering users and business partners.</p>
  
  <p>This is how my models look like</p>
  
  <pre><code>public class UserModel : IValidatableObject
  {
     //here are some properties and methods that I am using in Validate method        
  
      public CompanyModel Company { get; set; } //this is user Company
  
      public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {       
           if (this.UserWithEmailExists())
               yield return new ValidationResult("Email already exists", new[] { "Email" });
  
           if (this.UserWithUsernameExists())
               yield return new ValidationResult("Username already exists", new[] { "Username" });
      }
  }
  
  public class CompanyModel : IValidatableObject
  {
      //again here are some properties that i am using in Validate
  
      public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {
          if (this.Phone == null &amp;&amp; this.Mobile == null)
              yield return new ValidationResult("The Phone field is required", new[] { "Phone" });
      }
  }
  
  //this is the model passed to the view
  public sealed class RegistrationModel : UserModel, IValidatableObject
  {
      public new IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {
          if (this.Password != this.PasswordValidation)
              yield return new ValidationResult("Ponovite prejšnji vnos", new[] { "PasswordValidation" });
      }
  }
  </code></pre>
  
  <p>The problem is: When I submit my form Validate in CompanyModel is called and Validate in RegistrationModel too. But I want also Validate in UserModel to be called...</p>
  
  <p>UPDATE:
  I solved the first problem: These are the models after upgrading :)</p>
  
  <pre><code>public class UserModel : IValidatableObject
  {
     //here are some properties and methods that I am using in Validate method        
  
      public CompanyModel Company { get; set; } //this is user Company
  
      public virtual IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {       
           if (this.UserWithEmailExists())
               yield return new ValidationResult("Email already exists", new[] { "Email" });
  
           if (this.UserWithUsernameExists())
               yield return new ValidationResult("Username already exists", new[] { "Username" });
      }
  }
  
  public class CompanyModel : IValidatableObject
  {
      //again here are some properties that i am using in Validate
  
      public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {
          if (this.Phone == null &amp;&amp; this.Mobile == null)
              yield return new ValidationResult("The Phone field is required", new[] { "Phone" });
      }
  }
  
  //this is the model passed to the view
  public sealed class RegistrationModel : UserModel, IValidatableObject
  {
      public override new IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext validationContext)
      {
          //this is needed so that UserModel validation executes
          foreach (var result in base.Validate(validationContext))
          {
              yield return result;
          }
  
          if (this.Password != this.PasswordValidation)
              yield return new ValidationResult("Ponovite prejšnji vnos", new[] { "PasswordValidation" });
      }
  }
  </code></pre>
  
  <p>Now validation works fine. I just do not know why Validate in CompanyModel executes two times??. Any suggestion?</p>