title: How can I return additional (i.e. more than just field=>error message) validation information from custom validation code to the Controller or View?
body: <p>I am looking for a way to return the following information from my custom validation code:</p>
  
  <pre><code>public enum ValidationErrorTypeFlags
  {
      Error_Input = 1 &lt;&lt; 0,               // a "field specific" error which is checked both clientside and serverside 
      Error_Input_ServerSide = 1 &lt;&lt; 1,    // a "field specific" error which can only be checked serverside
      Error_General = 1 &lt;&lt; 2              // serverside general error
  }
  </code></pre>
  
  <p>Inside the validation code (either an IValidatableObject or a ValidationAttribute), when I detect an error, I would like to be able to associate one of the above error types with the ValidationResult.</p>
  
  <p>Then I want to be able to iterate through the validation errors in either the Controller or the View and distinguish between these error types.</p>
  
  <p>I'm currently using MVC 3 (happy to upgrade to 4).  </p>
  
  <p>NB:</p>
  
  <ul>
  <li>ModelState does not preserve ValidationResults AFAIK - you can only access errors in ViewData.ModelState.Values.Items[x].Errors - and these have been converted to System.Web.Mvc.ModelError</li>
  <li>It seems that MVC validation only allows you to access [key, 'error message'] type validation results after validation has completed. </li>
  </ul>
  
  <p>The hack I'm using at present is to decorate the error message inside the custom validation code:</p>
  
  <pre><code>var field = new[] { validationContext.DisplayName };
  return new ValidationResult("+Invalid format - use yyyy-mm-dd", field);
  </code></pre>
  
  <p>And then look for error messages which start with +,-,* in the controller.</p>