ASP.NET Web Api 2 - Change default validation messages for models site wide
<p>Say I have a model, like this:</p>

<pre><code>class Model
{
    [Required]
    public string Name { get; set; }
}
</code></pre>

<p>Is there a way to make it so that rather than the error message being:</p>

<blockquote>
  <p>The Name field is required.</p>
</blockquote>

<p>I can change it to:</p>

<blockquote>
  <p>Name is required.</p>
</blockquote>

<p>I would like to do this without making my own attributes and without adding an <code>ErrorMessage = x</code> to all of my attributes.</p>

<p>When searching I found some stuff that seemed to apply to MVC2, but nothing web api specific. I got as far as creating an attribute adapter:</p>

<pre><code>public class CustomRequiredAttributeAdapter : DataAnnotationsModelValidator&lt; RequiredAttribute&gt;
{
    public CustomRequiredAttributeAdapter(ModelMetadata metadata, ModelBindingExecutionContext context, RequiredAttribute attribute)
    : base(metadata, context, attribute)
    {
        attribute.ErrorMessage = "{0} is required.";
    }
}
</code></pre>

<p>But registering it like this:</p>

<pre><code>var validatorProvider = new DataAnnotationsModelValidatorProvider();
validatorProvider.RegisterAdapter(typeof(RequiredAttribute), typeof(CustomRequiredAttributeAdapter));       
webApiConfig.Services.Replace(typeof(System.Web.Http.Validation.ModelValidatorProvider), validatorProvider);
</code></pre>

<p>in my startup didn't seem to work.</p>