title: ASP.NET-MVC ; pass model to $.ajax function to perform server-side validation
body: <p>I need to do server side validation and that is send model to partial view. I am using $.ajax--> post--> json method to send and handle data, but I am failing to send validation model to partial view. </p>
  
  <h2>ajax method</h2>
  
  <pre><code>  $('#NewFunctionNavigationForm').submit(function (e) {
  
     e.preventDefault();
  
    var DataToPost =  JSON.stringify($('#NewFunctionNavigationForm').serializeObject());
  
    var formURL = $(this).attr("action");
  
    $.ajax({
        type: "POST",
        url: formURL,
        dataType: "JSON",
        contentType: "application/json; charset=utf-8",
        data: DataToPost,
    })
  .done(function (data, textStatus, jqXHR) {
  
      if (data.Response == "Success") {
  
          $(this).MyMessageDialog({
              _messageBlockID: "_StatusMessage",
              _messageContent: "Record Been Created Successfully",
              _messageBlockWidth: "300px"
          });
  
          $('div#_StatusMessage').on('dialogclose', function (event) {
              window.location = "/SystemCore/SystemCoreHome";
          });
      }
  
  })
  .fail(function (jqXHR, textStatus, errorThrown) {
  
      $(this).MyMessageDialog({
          _messageBlockID: "_StatusMessage",
          _messageContent: "Error In Creating Record! "+ textStatus + "  "+ errorThrown,
          _messageBlockWidth: "350px"
      });
  
      $('div#_StatusMessage').on('dialogclose', function (event) {
          window.location = "/SystemCore/SystemCoreHome";
      });
  });
  </code></pre>
  
  <p>});</p>
  
  <h2>razor form</h2>
  
  <pre><code>    @using (Html.BeginForm("CreateNewFunctionNavigation", "SystemCore", FormMethod.Post, new { id = "NewFunctionNavigationForm" }))
      {
              @Html.AntiForgeryToken()
  
              @Html.ValidationSummary(true)
           ... my fields here
     &lt;div class="form-group"&gt;
                  &lt;div class="col-md-offset-2 col-md-10"&gt;
                      &lt;input type="submit" value="Create" class="btn btn-default _formButton" /&gt;
                      &lt;input type="button" value="Cancel" class="btn btn-default _formButton" onclick="CancelPage();" /&gt;
                  &lt;/div&gt;
     &lt;/div&gt;
  }
  </code></pre>
  
  <h2>controller method</h2>
  
  <pre><code> [HttpGet]
      public ActionResult CreateNewFunctionNavigation()
      {
  
          return PartialView("CreateNewNavigation_Partial");
      }
  
  
   [HttpPost]
      public ActionResult CreateNewFunctionNavigation(CreateFunctionNavigation_SP_Map model )
      {
  
  
          if(ModelState.IsValid)
          {
              try
              {
                   _FN_Services_a2.CreateFunctionNavigation(model);
  
                   return Json(new { Response = "Success" });
              }
              catch (DataException ex)
              {
                  ModelState.AddModelError("", "Unable To Create New Function Navigation" + ex);
              }
          }
          else
          {
  
          }
          return PartialView("CreateNewNavigation_Partial", model);
          //return Json(new { Url = Url.Action("CreateNewNavigation_Partial", model) });
  
      } //end
  </code></pre>