title: Using jQuery validation with custom error messages with dynamically-generated forms
body: <p>I have a form that allows me to set values for multiple entities (books, for example) within a single HTML form. The ASP.NET MVC view for the page takes a model that contains a <code>List&lt;Book&gt;</code>. This is iterated over to render the form elements for each book.</p>
  
  <p>Let's imagine that my only validation rule is that book title is required.</p>
  
  <p>If the user fails to enter any book titles, then I want to highlight all relevant book title textboxes using a css class and display an alert that says "Book title is required" just once.</p>
  
  <p>I'd like to use the jQuery validation plugin to achieve this.</p>
  
  <p>The <a href="http://docs.jquery.com/Plugins/Validation/validate" rel="nofollow">documentation</a> tells us that if we want to set a custom error message for an element we do this using the <code>name</code> attribute of the relevant HTML form element in a <code>messages:</code> section of the <code>validate()</code> setup call.</p>
  
  <p>e.g. (where my HTML element has a <code>name</code> of <em>title</em>)</p>
  
  <pre><code>$(".selector").validate({
      rules: {
          title: "required",
      },
      messages: {
          title: "Book titles must be set",
      }
  })
  </code></pre>
  
  <p>However, this seems incompatible with how ASP.NET MVC model binding needs to use the <code>name</code> attribute, when binding to a list as it makes use of the <code>name</code> property of each form element using a very specific syntax, e.g.</p>
  
  <pre><code>&lt;form method="post" action="/Home/Create"&gt;
  
      &lt;input type="text" name="[0].Title" value="Curious George" /&gt;
      &lt;input type="text" name="[0].Author" value="H.A. Rey" /&gt;
      &lt;input type="text" name="[0].DatePublished" value="2/23/1973" /&gt;
  
      &lt;input type="text" name="[1].Title" value="Code Complete" /&gt;
      &lt;input type="text" name="[1].Author" value="Steve McConnell" /&gt;
      &lt;input type="text" name="[1].DatePublished" value="6/9/2004" /&gt;
  
      &lt;input type="text" name="[2].Title" value="The Two Towers" /&gt;
      &lt;input type="text" name="[2].Author" value="JRR Tolkien" /&gt;
      &lt;input type="text" name="[2].DatePublished" value="6/1/2005" /&gt;
  
      &lt;!-- There could be several more books in the form... --&gt;
  &lt;input type="submit" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>(taken from <a href="http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx" rel="nofollow">Haacked</a>)</p>
  
  <p>Are these conflicting usages of the <code>name</code> attribute a deal breaker as far as jQuery validation is concerned?</p>