title: JQuery Validate using addClassRules: What am I missing?
body: <p>I've put together a snippet of code in ASP.NET MVC in which I'm trying to use the addClassRules methods of jQuery's validator.  From what I can tell I'm taking this straight of the examples on</p>
  
  <p><a href="http://docs.jquery.com/Plugins/Validation/Reference" rel="nofollow noreferrer">http://docs.jquery.com/Plugins/Validation/Reference</a></p>
  
  <p>But the page is just submitted it doesn't show any errors.  I would like to use the "addClassRules" pattern for validation because I'm writing dynamic forms.</p>
  
  <p>Here's my View.</p>
  
  <pre><code>&lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage&lt;dynamic&gt;" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;ValidateMyForm&lt;/title&gt;
      &lt;script src="&lt;%= Url.Content("~/Scripts/jquery-1.4.1.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="&lt;%= Url.Content("~/Scripts/jquery.validate.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;% using (Html.BeginForm()) { %&gt;        
  
          &lt;input type="text" value="" name="customer1" class="customer" /&gt;
          &lt;input type="text" value="" id="customer2" name="customer2" class="customer" /&gt;
          &lt;input type="text" name="customer3" class="customer" /&gt;
  
          &lt;p&gt;
              &lt;input type="submit" name="submit" value="Submit" /&gt;
          &lt;/p&gt;
      &lt;% } %&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          jQuery(document).ready(function () {
              // alias required to cRequired with new message
              $.validator.addMethod("cRequired", $.validator.methods.required, "Customer name required");
              // alias minlength, too
              $.validator.addMethod("cMinlength", $.validator.methods.minlength, $.format("Customer name must have at least {0} characters"));
              // combine them both, including the parameter for minlength
              $.validator.addClassRules("customer", { cRequired: true, cMinlength: 2 });
          })
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Any suggestions?</p>
  
  <p><strong>UPDATED:  Fully functional code...</strong></p>
  
  <pre><code>&lt;%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage&lt;dynamic&gt;" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;ValidateMyForm&lt;/title&gt;
      &lt;script src="&lt;%= Url.Content("~/Scripts/jquery-1.4.1.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt;
      &lt;script src="&lt;%= Url.Content("~/Scripts/jquery.validate.js") %&gt;" type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;% using (Html.BeginForm(null, null, FormMethod.Post, new { id = "demoform" }))
          { %&gt;        
  
          &lt;%: Html.TextBox("myTextBox", "", new {@class = "cRequired"}) %&gt;
  
          &lt;p&gt;
              &lt;input type="submit" name="submit" value="Submit" /&gt;
          &lt;/p&gt;
      &lt;% } %&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          jQuery(document).ready(function () {
              $.validator.addClassRules("cRequired", { required: true });
  
              jQuery("#demoform").validate();
          })
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>