title: the required anti-forgery form field __requestverificationtoken is not present Error while ajax call
body: <blockquote>
    <p><a href="https://stackoverflow.com/questions/16793516/anti-forgery-form-field-requestverificationtoken-is-not-present-when-using-j">anti-forgery form field “__RequestVerificationToken” is not present
    when using jQuery Ajax and the Html.AntiForgeryToken()</a><br>
    <a href="https://stackoverflow.com/questions/19788916/how-to-make-ajax-request-with-anti-forgery-token-in-mvc">How to make ajax request with anti-forgery token in mvc</a><br>
    <a href="https://stackoverflow.com/questions/17857850/ajax-posting-validateantiforgerytoken-without-form-to-mvc-action-method">AJAX Posting ValidateAntiForgeryToken without Form to MVC Action Method</a>  </p>
  </blockquote>
  
  <p>All the answers above did not help me. I get this error in my request with Jquery Ajax call:</p>
  
  <blockquote>
    <p>"The required anti-forgery form field "__RequestVerificationToken" is
    not present"  </p>
  </blockquote>
  
  <p>If I comment  <code>[ValidateAntiForgeryToken]</code> attribute at POST action method it is working fine. I want to know why I am getting this error. </p>
  
  <pre><code>@using (Html.BeginForm("Save", "AddPost", FormMethod.Post, new { id = "CreateForm" }))
  {
      @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;GropPost_Table&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true)
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Body, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.TextBoxFor(model =&gt; model.Body, new { id = "Bf" })
                  @Html.ValidationMessageFor(model =&gt; model.Body)
              &lt;/div&gt;
          &lt;/div&gt;
  
  
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10"&gt;
                  &lt;input id="btnAdd" value="Create" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  }  
  </code></pre>
  
  <hr>
  
  <pre><code>  [HttpPost]
          [ValidateAntiForgeryToken]
          public JsonResult Save([Bind(Include = "Body")] GropPost_Table groppost_table)
          {
  
              if (ModelState.IsValid)
              {
  
                  groppost_table.GroupID = 1;
                  groppost_table.ID = 1;
                  groppost_table.PostDate = System.DateTime.Now;
                  db.GropPost_Table.Add(groppost_table);
                  db.SaveChanges();
                  return Json(groppost_table);
              }
  
              else
              {
  
                  return Json("we Couldent add your post");
              }
          }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      $("#btnAdd").click(function () {
  
          var GropPost_Table = {
              "Body": $("#Bf").val()       
          };
  
          var token = $('#CreateForm input[name=__RequestVerificationToken]').val()
  
          var headers = {};
  
          headers['__RequestVerificationToken'] = token;
  
  
          $.ajax( {
              type: "POST",
              url: "@Url.Action("Save","AddPost")",
              data: JSON.stringify(GropPost_Table),
              contentType: "application/json;charset=utf-8",
              processData: true,
              headers:headers,
              success: function (dataR) {
                  $("#Bf").val('');
             },
              error: function (dataR) {
                  $("#Bf").val('');
                  alert(dataR.toString());
              }
          });
      });
      &lt;/script&gt;
  </code></pre>