title: How to format error message from a custom validator
body: <p>I have created a custom validator this way:</p>
  
  <pre><code>public class IntArrayRequiredAttribute : ValidationAttribute
  {
      protected override ValidationResult IsValid(object value, ValidationContext validationContext)
      {
          if ((!(value is int[] array) || !array.Any() || array.Any(item =&gt; item == 0)))
              return new ValidationResult(this.ErrorMessage);
  
          return ValidationResult.Success;
      }
  }
  </code></pre>
  
  <p>and apply it to a model property:</p>
  
  <pre><code>    [IntArrayRequiredAttribute(ErrorMessage = "You must select {0}.")]
      [Display(Name = "Rol")]
      public int[] Roles { get; set; }
  </code></pre>
  
  <p>Well, when the validation fails, this error is shown:</p>
  
  <p><code>"You must select {0}."</code></p>
  
  <p>How can I return the error message so that {0} is replaced by the display name of the field automatically, such as the built-in validators?</p>
  
  <p>Expected result should be <code>"You must select Rol."</code></p>
  
  <p>EDIT:</p>
  
  <p>By Seeing ValidationAttribute source code, I read:</p>
  
  <pre><code>    public ValidationResult GetValidationResult(object value, ValidationContext validationContext) {
          if (validationContext == null) {
              throw new ArgumentNullException("validationContext");
          }
  
          ValidationResult result = this.IsValid(value, validationContext);
  
          // If validation fails, we want to ensure we have a ValidationResult that guarantees it has an ErrorMessage
          if (result != null) {
              bool hasErrorMessage = (result != null) ? !string.IsNullOrEmpty(result.ErrorMessage) : false;
              if (!hasErrorMessage) {
                  string errorMessage = this.FormatErrorMessage(validationContext.DisplayName);
                  result = new ValidationResult(errorMessage, result.MemberNames);
              }
          }
  
          return result;
      }
  </code></pre>
  
  <p>I saw that it calls my overridden IsValid method and it formats the message. Why isn't it formatting in my case?</p>
  
  <p>If I use the IsValid overload, it formats correctly, however, I need to use this method because I need validationContext for other validation purpose.</p>