title: How to provide warnings during validation in ASP.NET MVC?
body: <p>Sometimes user input is not strictly invalid but can be considered problematic.</p>
  
  <p>For example:</p>
  
  <ul>
  <li>A user enters a long sentence in a single-line <code>Name</code> field. <em>He probably should
  have used the <code>Description</code> field instead</em>.</li>
  <li>A user enters a <code>Name</code> that is very similar to that of an existing entity. <em>Perhaps he's inputting the same entity but didn't realize it already exists, or some concurrent user has just entered it.</em></li>
  </ul>
  
  <p>Some of these can easily be checked client-side, some require server-side checks.</p>
  
  <p><strong>What's the best way</strong>, perhaps something similar to <code>DataAnnotations</code> validation, <strong>to provide warnings to the user in such cases?</strong> The key here is that the user has to be able to override the warning and still submit the form (or re-submit the form, depending on the implementation).</p>
  
  <p>The most viable solution that comes to mind is to create some attribute, similar to a <code>CustomValidationAttribute</code>, that may make an AJAX call and would display some warning text but doesn't affect the <code>ModelState</code>. The intended usage is this:</p>
  
  <pre><code>[WarningOnFieldLength(MaxLength = 150)]
  [WarningOnPossibleDuplicate()]
  public string Name { get; set; }
  </code></pre>
  
  <p>In the view:</p>
  
  <pre><code>@Html.EditorFor(model =&gt; model.Name)
  @Html.WarningMessageFor(model =&gt; model.Name)
  @Html.ValidationMessageFor(model =&gt; model.Name)
  </code></pre>
  
  <p>So, any ideas?</p>