我为包含@Html.AntiForgeryToken() 的表单所做的ajax 帖子存在问题。
当我通过 ajax 发布表单时,我得到以下查询字符串: http://myhost.local/Assessment/NextQuestion/15?__RequestVerificationToken=HVHkyjrwWupa9pU6tiMVjSDept5XeBtCyNL0tHwWEkfFDHJLXps9oRG7AlfvVHOx0tK0pE78KaQMD7gL5YBBXu_TfKhC3bPd69WaGCldFt2PQ
如何从查询字符串中删除它?执行标准帖子时,查询字符串不包含此内容。
形式:
@using (Html.BeginForm("NextQuestion", "Assessment", FormMethod.Post, new { @class = "form-vertical"}))
{
@Html.AntiForgeryToken()
....
}
发布功能:
$('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;
}));
行动方法:
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult NextQuestion(AssessmentModel model)