title: Model validation in Asp.Net Core before making an Ajax call from java script
body: <p>Below is the sample code, i am calling this code on button click event. My question is, can i validate my viewmodel object before making ajax call? i can see model errors in java script, not sure how to check.
  My <strong>viewmodel</strong> class properties has Data Annotation Validator Attributes. I don't want make ajax call if the viewmodel is not valid, want to check (ModelState.IsValid) in java script code, before making ajax call.
  Any help, would be greatly appreciated.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(function () {
      $("#btnGet").click(function () {
          var viewModelobject = {};
          viewModelobject.Name = $("#txtName").val();
          $.ajax({
              type: "POST",
              url: "/Home/AjaxMethod",
              data: viewModelobject,
              contentType: "application/json",
              dataType: "json",
              success: function (response) {
                  alert("Hello")
              }
          });
      });
  }</code></pre>
  </div>
  </div>
  </p>