title: AJAX Post to ASP.NET core MVC 6 Controller action method and parameters are null
body: <p>However, in the controller the params are always null/default values. Please see my code below and let me know if I am making a silly mistake or something.</p>
  
  <p><a href="https://i.stack.imgur.com/cPK8i.jpg" rel="nofollow noreferrer">Plz see image</a></p>
  
  <p><strong>Here is my controller's action method:</strong></p>
  
  <pre><code>[HttpPost]
  public JsonResult AjaxMethodTemp([FromBody]UserAccount user)
  {
      //string Name = name + DateTime.Now.ToString();
  
      //return Json(Name);
      try
      {
          //if (ModelState.IsValid)
          //{
              _context.userAccount.Add(user);
              _context.SaveChanges();
              ModelState.Clear();
  
              ViewBag.Massege = user.FirstName + "_" + user.LastName + " is Successfully Registered";
          //}
      }
      catch (DbUpdateException /* ex */)
      {
          //Log the error (uncomment ex variable name and write a log.
          ModelState.AddModelError("", "Unable to save changes. " +
              "Try again, and if the problem persists " +
              "see your system administrator.");
      }
      return Json(user.FirstName + "_" + user.LastName + " is Successfully Registered");
  
  }
  </code></pre>
  
  <p><strong>Here is my AJAX post:</strong></p>
  
  <pre><code>function SaveCity() {
      debugger
      var $form = $('#contactForm');
      $form.removeData('validator');
      $form.removeData('unobtrusiveValidation');
      $.validator.unobtrusive.parse($form);
      $form.validate();
      if ($form.valid()) {
  
          $.ajax({
              type: "POST",
              url: "/Home/AjaxMethodTemp",
              //url:"/api/users",
              contentType: "application/json; charset=utf-8",
              data:
                  {
                      Password: "abc",
                      UserName: "abc",
                      Email: "abc@gmail.com",
                      FirstName: "abc",
                      LastName: "abc"
                  },
              //data: JSON.stringify({
              //    FirstName: $('#FirstName').val(),
              //    LastName: $("#LastName").val(),
              //    Email: $("#Email").val(),
              //    UserName: $("#UserName").val(),
              //    Password: $("#Password").val()
              //}),
              success: function (data) {
              }
  
          });
  
      }
  }
  </code></pre>
  
  <p><strong>Here is my Form Data:</strong></p>
  
  <pre><code>&lt;form id="contactForm"&gt;
      @* asp-controller="Home" asp-action="AjaxMethod method="post""*@
      @if (ViewBag.Massege != null)
      {
          &lt;div class="form-control"&gt;
              &lt;div class="col-md-10"&gt;@ViewBag.Massege&lt;/div&gt;
          &lt;/div&gt;
      }
  
      &lt;div class="form-group"&gt;
          &lt;label asp-for="FirstName" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="FirstName" id="FirstName" class="form-control" /&gt;
              &lt;span asp-validation-for="FirstName" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="LastName" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="LastName" id="LastName" class="form-control" /&gt;
              &lt;span asp-validation-for="LastName" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="Email" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="Email" id="Email" class="form-control" /&gt;
              &lt;span asp-validation-for="Email" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="UserName" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="UserName" id="UserName" class="form-control" /&gt;
              &lt;span asp-validation-for="UserName" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="Password" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="Password" id="Password" class="form-control" /&gt;
              &lt;span asp-validation-for="Password" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label asp-for="ConfirmPassword" class="col-md-2 control-label"&gt;&lt;/label&gt;
          &lt;div class="col-md-10"&gt;
              &lt;input asp-for="ConfirmPassword" class="form-control" /&gt;
              &lt;span asp-validation-for="ConfirmPassword" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              @*&lt;button type="submit" class="btn btn-default" id="btn1"&gt;Register&lt;/button&gt;*@
  
              @*&lt;input type="button" id="btnGet" value="Get Current Time" /&gt;*@
              &lt;input type="submit" name="Sumbit" onclick="SaveCity(); return false;" /&gt;
              @*&lt;a class="delete-link" h&gt;Delete&lt;/a&gt;*@
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Here is the Model :</strong></p>
  
  <pre><code>public class UserAccount
  {
      [Key]
      public int UserID { get; set; }
  
      [Required(ErrorMessage ="First Name Required")]
      public string FirstName { get; set; }
  
      [Required(ErrorMessage ="Last Name Required")]
      public string LastName { get; set; }
  
      [Required(ErrorMessage ="Email Required")]
      [DataType(DataType.EmailAddress)]
      public string Email { get; set; }
  
      [Required(ErrorMessage ="User Name Required")]
      public string UserName { get; set; }
  
      [Required(ErrorMessage ="Password Required")]
      [DataType(DataType.Password)]
      public string Password { get; set; }
  
      [Compare("Password",ErrorMessage ="Password Not Match")]
      [DataType(DataType.Password)]
      public string ConfirmPassword { get; set; }
  }
  </code></pre>
  
  <p>Any one have idea than plz help me...</p>