title: Property-level validation errors hinder the validation of Class-level validation
body: <p><strong>Update after Bounty was awarded</strong></p>
  
  <p>A new solution is coming up to this problem. Please refer to ASP.NET MVC 3 Preview 1 here: <a href="http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx</a></p>
  
  <p>Look in the section <strong>Model Validation Improvements</strong>, where you will see the solution to my problem.</p>
  
  <hr>
  
  <p><strong>Original Post</strong></p>
  
  <p>Referring to my earlier post <a href="https://stackoverflow.com/questions/2450198/how-to-validate-two-properties-with-asp-net-mvc-2">How to validate two properties with ASP.NET MVC 2</a> where I asked how I could compare two properties for Model validation.</p>
  
  <p>I did find the answer useful, but I was left with an entirely different problem:</p>
  
  <p><strong>Problem</strong>: If a Property-level ValidationAttribute contains an error, then the Class-level ValidationAttributes are NOT validated.</p>
  
  <p>Please consider the following:</p>
  
  <pre><code>[EqualTo("Email", "EmailConfirm", ErrorMessage = "E-mailadresserne skal være ens")]
  [EqualTo("Password", "PasswordConfirm", ErrorMessage = "Adgangskoderne skal være ens")]
  [Bind(Exclude="UserId")]
  public class EditSiteUser
  {
      [Required(ErrorMessage="Du skal bekræfte adgangskode")]
      public string PasswordConfirm { get; set; }
  
      [Required(ErrorMessage="Du skal bekræfte e-mailadressen")]
      [Email(ErrorMessage="Ugyldig e-mailadresse")]
      public string EmailConfirm { get; set; }
      public int UserId { get; set; }
  
      [Required(ErrorMessage = "Du skal indtaste et brugernavn")]
      public string Username { get; set; }
  
      [Required(ErrorMessage = "Du skal indtaste en adgangskode")]
      public string Password { get; set; }
  
      [Required(ErrorMessage = "Du skal indtaste en e-mailadresse")]
      [Email(ErrorMessage = "Ugyldig e-mailadresse")]
      public string Email { get; set; }
  }
  </code></pre>
  
  <p>Here I have two Class-level attibutes that validate EmailConfirm and PasswordConfirm.</p>
  
  <p>If a field like Username is empty, and thus yields an error, then the two EqualTo Attributes are never validated.</p>
  
  <p>Does anyone have a suggestion to overcome this problem?</p>
  
  <p>EDIT: If you need anymore information about this problem, please ask in comments and I will be very happy to give you any additional information you need.</p>
  
  <h2>Questions:</h2>
  
  <p>Q: "Why is it important that the class-level checks get validated if a property-level check fails?".</p>
  
  <p>A: "Because this is part of a form, where a user enters information into a form that posts back via AJAX. When the form returns it should show all current problems."</p>
  
  <p>Q: "What exactly is the EqualTo attribute you have placed on the class? Is it a custom validation attribute? If so, how does it work? what does it do?"</p>
  
  <p>A: EqualTo is a class-level ValidationAttribute that compares the value of two Properties of the class-instance. Look up "PropertiesMustMatchAttribute" for a similar implementation.</p>