here is another obstacle for me, I want my site to remain cross-site attacks, I am developing a Master / Detail form using asp.net mvc 5 through an Ajax request. So, to create one entry, I have to go through the Ajax request process, as follows:
$.ajax({
url: '/Sales/Create',
data: JSON.stringify(salesmain),
type: 'POST',
contentType: 'application/json;',
dataType: 'json',
success: function (result) {
if (result.Success == "1") {
window.location.href = "/Sales/index";
}
else {
alert(result.ex);
}
}
});
now it does not move to the βCreateβ action in the sales controller, as the ajax request says, and before that it throws the following exception:
The required form field for counterfeiting "__RequestVerificationToken" is missing.
google, , , , __RequestVerificationToken jquery , JSON.stringify(salesmain) , :
$.ajax({
.
.
addRequestVerificationToken(JSON.stringify(salesmain))
:
function addRequestVerificationToken(data) {
data.__RequestVerificationToken = $('input[name=__RequestVerificationToken]').val();
return data;
};
, :
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
.
.
:
[HttpPost]
[ValidateAntiForgeryToken]
public JsonResult Create([Bind(Include = "SalesId,ReferenceNo,SalesDate,SalesPerson")] SalesMain salesMain)
{
.
.
jQuery 1.5, , , , , ? HELP , Advance:)