title: ASP.NET MVC validation not working on bootstrap modal
body: <p>I can't get the bootstrap modal and asp.net mvc validation start working together. I've got a complex form with some validation displayed in bootstrap modal. Unfortunetely when I hit the submit button the validation doesn't work at all.</p>
  
  <p>The form uses standard asp.net mvc validation. Below there is a part of it just to get the idea of how it is build:</p>
  
  <pre><code>@using (Html.BuildForm().AddClass("form-horizontal").Id("contact-add-popup").EncType(FormEncType.MultipartData).Begin()) {
  @Html.AntiForgeryToken()
  @Html.Partial("_Alerts")
  &lt;div class="control-group"&gt;
  
  &lt;div class="control-group company-field"&gt;
      @Html.BuildLabelFor(m =&gt; m.Name).AddClass("control-label")
      &lt;div class="controls"&gt;
          @Html.BuildTextBoxFor(m =&gt; m.Name).AddClass("input-xxlarge")
          @Html.ValidationMessageFor(m =&gt; m.Name)
      &lt;/div&gt;
  &lt;/div&gt;
  (...)
  </code></pre>
  
  <p>Here is my modal:</p>
  
  <pre><code>&lt;div id="createContactModal" class="modal hide fade modal-contact" tabindex="-1" role="dialog" aria-labelledby="createContactModalLabel" aria-hidden="true" data-backdrop="static"&gt;
  &lt;div class="modal-header"&gt;
      &lt;h4 class="modal-label" id="createContactModalLabel"&gt;Add contact&lt;/h4&gt;
  &lt;/div&gt;
  &lt;div class="modal-body"&gt;
      @Html.Partial("_CreateContact", new ContactCreateModel())
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
      &lt;a href="javascript:$('#contact-add-popup').submit();" class="btn btn-primary"&gt;Zapisz&lt;/a&gt;
      &lt;button class="btn" data-dismiss="modal" aria-hidden="true"&gt;Zamknij&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>And some javascript that I hope to get the validation working:</p>
  
  <pre><code>        $('#createContactModal').on('shown', function () {
              $("#contact-add-popup").removeData("validator");
              $("#contact-add-popup").removeData("unobtrusiveValidation");
              $.validator.unobtrusive.parse("#contact-add-popup");
          });
  
          $('#contact-add-popup').on('submit', function(e){
              e.preventDefault();
  
              $.validator.unobtrusive.parse($("#contact-add-popup"));
  
              if ($('#contact-add-popup').valid()){
                  alert('AJAX');
              }
          }); 
  </code></pre>
  
  <p>The line if ($('#contact-add-popup').valid()) returns always true. How can I get the modal and validation to work?</p>