title: Check all validations with jquery before posting in asp.net mvc 5
body: <p>I want to post my MVC form with jquery . My view model is this</p>
  
  <pre><code> public class DemoViewModel
    {
      [Required]
      public string  FirstName { get; set; }
      [Required]
  
      public string LastName { get; set; }
    }
  </code></pre>
  
  <p>and my controller is</p>
  
  <pre><code>  [HttpPost]
      public JsonResult LongRunningDemoProcess(DemoViewModel model)
      {
          Thread.Sleep(1000);
          return Json(model, "json");
      }
  </code></pre>
  
  <p>and my view has the following code</p>
  
  <pre><code>@model WebApplication2.Models.DemoViewModel
  @{
      ViewBag.Title = "Home Page";
  }
  
  
  
  @using (Html.BeginForm("LongRunningDemoProcess", "Home", FormMethod.Post,
  new { encType = "multipart/form-data", id = "myform", name = "myform" }))
  {
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.FirstName,
          new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.FirstName)
              @Html.ValidationMessageFor(model =&gt; model.FirstName)
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          @Html.LabelFor(model =&gt; model.LastName,
          new { @class = "control-label col-md-2" })
          &lt;div class="col-md-10"&gt;
              @Html.EditorFor(model =&gt; model.LastName)
              @Html.ValidationMessageFor(model =&gt; model.LastName)
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;input type="submit" name="operation" id="process" value="process" /&gt;
  }
  
  &lt;div id="divProcessing"&gt;
      &lt;p&gt;Processing, please wait . . . &lt;img src="../../Content/ajax-loader.gif"&gt;&lt;/p&gt;
  &lt;/div&gt;
  
  &lt;div id="divResult"&gt;
  
  &lt;/div&gt;
  
  @section Scripts {
      @Scripts.Render("~/bundles/jqueryval")
  
      &lt;script type="text/javascript"&gt;
  
          $(document).ready(function () {
  
              // Hide the "busy" Gif at load:
              $("#divProcessing").hide();
  
              // Handle the form submit event, and make the Ajax request:
              $("#myform").on("submit", function (event) {
                  event.preventDefault();
                   // Show the "busy" Gif:
                  $("#divProcessing").show();
                  var url = $(this).attr("action");
                  var formData = $(this).serialize();
                  $.ajax({
                      url: url,
                      type: "POST",
                      data: formData,
                      dataType: "json",
                      success: function (resp) {
                          // Hide the "busy" gif:
                          $("#divProcessing").hide();
  
                          // Do something useful with the data:
                          $("&lt;h3&gt;" + resp.FirstName + " " + resp.LastName + "&lt;/h3&gt;").appendTo("#divResult");
                      }
                  })
              });
          });
  
      &lt;/script&gt;
  }
  </code></pre>
  
  <p>but the problem is that even if their are errors of required field the form is posted and get the result</p>
  
  <p><img src="https://i.stack.imgur.com/ZNiu8.png" alt="enter image description here"></p>
  
  <p>I tried to test this code <code>if($("#myform").valid())</code> but there is no method available .
  How can I test the validation by using jquery.validate.js as it is included already.
  Thanks</p>