title: reading ajax request body values by name with asp.net mvc 5 action controller
body: <p>i want to access jquery ajax post request body to get the value on my asp.net mvc 5 controller action.
  knowing that i m passing __RequestVerificationToken with success.</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(
         function () {
             $("#renamedashboard").click(function () {
                 swal({
                     title: "Titre Dashboard",
                     text: "Saisir le nouveau titre:",
                     type: "input",
                     showCancelButton: true,
                     closeOnConfirm: false,
                     animation: "slide-from-top",
                     inputType : "text"
                 },
                 function (inputValue)
                 {
                     if (inputValue === false)
                         return false;
                     if (inputValue === "")
                     {
                         swal.showInputError("You need to write something!");
                         return false
                     }
                     alert(inputValue);
                     var form = $('#__AjaxAntiForgeryForm');
                     //form.append('&lt;input type="hidden" name="name" value=' + inputValue + ' /&gt;');
                     var token = $('input[name="__RequestVerificationToken"]', form).val();
                     $.ajax({
                         url: ($(this).data('url')),// i tried to do ($(this).data('url'))+'?name='+inputValue but i got undefined id
                         type: "POST",
                         data: {
                             name: inputValue,
                             __RequestVerificationToken: token
                         },
                         success: SuccessCallback,
                         error: FailureCallback
                     });
                 });
                 function SuccessCallback(data) {
                     swal({
                         title: "Opération réussie",
                         type: "success"
  
                     }, function () {
                         NProgress.done();
                         location.reload();
                     });
                 }
                 function FailureCallback(data) {
                     swal("Good job!", "You clicked the button!", "error");
                     NProgress.done();
                 }
  
             });});
  </code></pre>
  
  <p>
  here is my controller </p>
  
  <pre><code>        [HttpPost]
      [ValidateAntiForgeryToken]
      // POST: Dashboard/Rename/5
      public async Task&lt;ActionResult&gt; Rename(int id,[System.Web.Http.FromBody] string name)
      {
          Dashboard dashboard = await dbs.Dashboards.FindAsync(id);
          //dashboard.Visible = true;
          dashboard.TitreD = name.ToString();
          dbs.Entry(dashboard).State = EntityState.Modified;
          await dbs.SaveChangesAsync();
          return Json(new { success = true });
      }
  </code></pre>
  
  <p>i have a hidden form on my view </p>
  
  <pre><code>@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "__AjaxAntiForgeryForm" })){
  @Html.AntiForgeryToken()
  }
  </code></pre>
  
  <p>the body content is<br>
  name|test<br>
  __RequestVerificationToken|the token  </p>