Follow the code:
//AntiForgeryToken
function gettoken() {
var token = '@Html.AntiForgeryToken()';
token = $(token).val();
return token;
}
Ajax and formData:
var formData = new FormData();
var file = document.getElementById("imageFile").files[0];
var file1 = document.getElementById("coverFile").files[0];
$.ajax({
cache: false,
type: "POST",
url: 'ação controller',
data: {formData, gettoken}, <- como fazer aqui
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
if (response) {
}
}
,
error: function (request, status, error)
{
alert('Error')
}
});
PartialView:
<form id="myform">
<div class="modal-body">
Campos...
</div>
<input type="submit" class="btn btn-success" value="Criar" />
</form>
How to make AntiForgeryToken via Ajax to protect against counterfeiting? Any solution?