I have an issue with ajax posts I'm doing for a form that contains @Html.AntiForgeryToken().
When I post the form via ajax I get the following query string: http://myhost.local/Assessment/NextQuestion/15?__RequestVerificationToken=HVHkyjrwWupa9pU6tiMVjSDept5XeBtCyNL0tHwWEkfFDHJLXps9oRG7AlfvVHOx0tK0pE78KaQMD7gL5YBBXu_TfKhC3Pd69WaGCldFhPQhbP2t0
How do I remove this from the query string? The query string doesn't contain this when doing a standard post.
Form:
@using (Html.BeginForm("NextQuestion", "Assessment", FormMethod.Post, new { @class = "form-vertical"}))
{
@Html.AntiForgeryToken()
....
}
Post function:
$('form.ajaxForm').on('submit', (function() {
$("#loadingIndicator").show();
$.ajax(
{
type: "POST",
url: $('form.ajaxForm').attr("action"),
data: $('form.ajaxForm').serialize(),
success:
function(result) {
$("#loadingIndicator").hide();
if (result.redirect) {
window.location.href = result.redirect;
return;
} else {
alert(result.ValidationMessage());
}
},
error:
function(req, status, err) {
alert('error');
$("#loadingIndicator").hide();
},
});
return false;
}));
Action Method:
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult NextQuestion(AssessmentModel model)