title: Validate a form loaded in ajax using jQuery validation and MVC
body: <p>First, I read this <a href="https://stackoverflow.com/questions/16579155/jquery-validation-form-with-ajax-loaded-form">question</a> already but it doesn't answer to my issue.</p>
  
  <p>Let's say I have a model:</p>
  
  <pre><code>public class MyModel {
     [Required]
     public string Email { get; set; }
  
     public string Text { get; set; }
  }
  </code></pre>
  
  <p>and a partial view  _MyForm.cshtml :</p>
  
  <pre><code>@model MyModel
  &lt;form&gt;
     @Html.LabelFor(m=&gt;m.Email)
     @Html.TextBoxFor(m=&gt;m.Email)
     &lt;br /&gt;
     @Html.LabelFor(m=&gt;m.Text)
     @Html.TextBoxFor(m=&gt;m.Text)
    &lt;br/&gt;
     &lt;input type="submit" value="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>An action which returns that partial view</p>
  
  <pre><code>public PartialViewResult GetView(){
     return PartialView("_MyForm", new MyModel());
  }
  </code></pre>
  
  <p>and I call that view via ajax</p>
  
  <pre><code>$.ajax({
     url: "/Home/GetView",
     dataType: "html",
     success: function(html) {
         $("#aDiv").html(html);
  
         $("#aDiv :submit").on("click", function (){
             $(this).closest("form").validate({
                submitHandler: function (){  alert('valid'); }
             });
         }); 
     }
  });
  </code></pre>
  
  <p>The problem, is I don't fill the e-mail field, alert dialog is displayed instead to make email (which is required) field with red border.</p>
  
  <p>If I don't call that view using ajax, and I use <code>Html.RenderPartial('_MyForm', new MyModel())</code> inside a view then it works.</p>
  
  <p>With other words, if that partial view is rendered normally (by calling <code>RenderPartial</code>) then validation works, if it is rendered through ajax then validation is not working.</p>
  
  <p>Why ? I have no error, I log the <code>html</code> parameter from <code>success</code> function, seems to be ok.</p>