I'm using jQuery DataTales to request a POST URL from MVC5 and trying to add an anti-forgery token. I've added it to both the headers and also the request body, but still get a 500 error: "The required anti-forgery form field "__RequestVerificationToken" is not present."
The form:
<form id="my-units-form" action="@Url.Action("MyUnitsResults", "Provider")" class="form-horizontal criteria well well-sm">
@Html.AntiForgeryToken()
....
The JavaScript:
$userDt = $('#users-table')
.DataTable({
serverSide: true,
ordering: false,
searching: true,
ajax: {
"url": url,
"type": "POST",
'contentType': 'application/json',
"dataType": "json",
headers: { '__RequestVerificationToken': $('form input[name=__RequestVerificationToken]').val() },
data: function (d) {
d.__RequestVerificationToken= $('form input[name=__RequestVerificationToken]').val();
return JSON.stringify(d);
}
},

