title: How to add custom validate method for viewmodel
body: <p>I tried to add custom validator for ViewModel class:</p>
  
  <pre><code>[Serializable]
  public class UserViewModel : IValidatableObject 
  {
      public IEnumerable&lt;ValidationResult&gt; Validate(ValidationContext context)
      {
          yield return new ValidationResult("Fail this validation");
      }
  }
  </code></pre>
  
  <p>Unfortunately this is not triggered when Action method gets called, e.g.</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Edit(UserViewModel user)
  </code></pre>
  
  <p>How can I add custom validation logic? ValidationAttribute does not provide easy enough solution. I am unable to find clear information on MVC2 validation mechanisms.</p>