title: How to prevent a modal popup windows from submitting the form in-case it have validation errors
body: <p>I am working on an asp.net mvc5 web application, and i am implementing CRUD operations using Bootstrap &amp; WebGrid. </p>
  
  <p>now my Create action methods looks as follow:-</p>
  
  <pre><code> [HttpGet]
          public ActionResult Create()
          {
              var phone = new Phone();
              return PartialView("Create", phone);
          }
  
  
          // POST: /Phone/Create
          [HttpPost]
          public JsonResult Create(Phone phone)
          {
              if (ModelState.IsValid)
              {
                  db.Phones.Add(phone);
                  db.SaveChanges();
                  return Json(new { success = true });
              }
              return Json(phone, JsonRequestBehavior.AllowGet);
          }
  </code></pre>
  
  <p>and the Index view which have a Create button that will open the popup window:-</p>
  
  <pre><code> &lt;div class="pull-right col-lg-1"&gt;   
                  &lt;a class="btn btn-success" data-modal="" href="/Phone/Create" id="btnCreate"&gt;
                       &lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;      
                  &lt;/a&gt;
              &lt;/div&gt;
  &lt;div id='myModal' class='modal fade in'&gt;
      &lt;div class="modal-dialog"&gt;
          &lt;div class="modal-content"&gt;
              &lt;div id='myModalContent'&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  @section scripts{
      @Scripts.Render("~/scripts/appjs/phones.js")
  }
  </code></pre>
  
  <p>an the phones.js is :-</p>
  
  <pre><code>  $(function () {
          $.ajaxSetup({ cache: false });
          $("a[data-modal]").on("click", function (e) {        
              $('#myModalContent').load(this.href, function () {
                  $('#myModal').modal({
                      keyboard: true
                  }, 'show');
  
                  bindForm(this);
              });
              return false;
          });
  
  
      });
  
      function bindForm(dialog) {
          $('form', dialog).submit(function () {
              $('#progress').show();
              $.ajax({
                  url: this.action,
                  type: this.method,
                  data: $(this).serialize(),
                  success: function (result) {
                      if (result.success) {
                          $('#myModal').modal('hide');
                          $('#progress').hide();
                          location.reload();
                      } else {
                          $('#progress').hide();
                          $('#myModalContent').html(result);
                          bindForm();
                      }
                  }
              });
              return false;
          });
      }
  </code></pre>
  
  <p>the Create view:-</p>
  
  <pre><code>  @model MvcBootstrapCrud.Models.Phone
  
      &lt;div class="modal-header"&gt;
          &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;×&lt;/button&gt;
          &lt;h3 class="modal-title"&gt;Add New Phone&lt;/h3&gt;
      &lt;/div&gt;
  
  
      @using (Html.BeginForm())
      {
          @Html.AntiForgeryToken()
  
          &lt;div class="modal-body"&gt;
  
              &lt;div class="form-horizontal"&gt;
                  &lt;div class="form-group"&gt;
                      @Html.LabelFor(m =&gt; Model.Model, new { @class = "control-label col-sm-3" })
                      &lt;div class="col-sm-9"&gt;
                          @Html.TextBoxFor(m =&gt; m.Model, new { @class = "form-control required" })
                          &lt;div&gt;
                              @Html.ValidationMessageFor(m =&gt; m.Model)
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div class="form-group"&gt;
                      @Html.LabelFor(m =&gt; Model.Company, new { @class = "control-label col-sm-3" })
                      &lt;div class="col-sm-9"&gt;
                          @Html.TextBoxFor(m =&gt; m.Company, new { @class = "form-control required" })
                          &lt;div&gt;
                              @Html.ValidationMessageFor(m =&gt; m.Company)
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div class="form-group"&gt;
                      @Html.LabelFor(m =&gt; Model.Price, new { @class = "control-label col-sm-3" })
                      &lt;div class="col-sm-9"&gt;
                          @Html.TextBoxFor(m =&gt; m.Price, new { @class = "form-control required" })
                          &lt;div&gt;
                              @Html.ValidationMessageFor(m =&gt; m.Price)
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="modal-footer"&gt;
              &lt;span id="progress" class="text-center" style="display: none;"&gt;
                  &lt;img src="/images/wait.gif" alt="wiat" /&gt;
                  Wait..
              &lt;/span&gt;
  
              &lt;input class="btn btn-primary" type="submit" value="Save" /&gt;
              &lt;button class="btn btn-warning" data-dismiss="modal"&gt;Close&lt;/button&gt;
          &lt;/div&gt;
      }
      &lt;script&gt;
          $("form").removeData("validator");
          $("form").removeData("unobtrusiveValidation");
          $.validator.unobtrusive.parse("form");
      &lt;/script&gt;
  </code></pre>
  
  <p>and the Phone model class:-</p>
  
  <pre><code>public class Phone
      {
          [Display(Name = "ID")]
          [Key]
          public int PhoneId { get; set; }
  
          [Required]
          [Display(Name = "Model Name")]
          public string Model { get; set; }
  
          [Required]
          [Display(Name = "Company Name")]
          public string Company { get; set; }
  
          [Required]
          [Display(Name = "Price")]
          [DataType(DataType.Currency)]
          public decimal Price { get; set; }
      }
  </code></pre>
  
  <p>The problem i am facing is that when the Create modal popup form is shown , and the user leave a Required field empty ,  a validation error will be shown beside the field (as defined in the [Required] data annotation). but the validation error will not prevent the popup from submitting the form when the user click on Save button ,and the Post Create action method are going to be called even with the validation error being shown.. so can anyone adivce on this please?
  Thanks </p>