2
Follows 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 ?
What exactly do you want to do? You didn’t explain anything in the question...
– André
would that be? http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-with-jquery-and-ajax
– Renato Colaço