3
我與[ValidateAntiForgeryToken]
屬性有問題。ValidateAntiForgeryToken錯誤
我通過jQuery將__RequestVerificationToken
發送到服務器,但服務器響應錯誤。
我傳遞給服務器的數據是兩個類,當我只發送一個類時請求成功完成。
這裏是我的代碼:
var form = $('#__AjaxAntiForgeryForm');
var token = $('input[name="__RequestVerificationToken"]', form).val();
var ProductRegisterVm =
{
"Price": $scope.Product.Price,
"CanSend": $scope.Product.CanSend,
"Changeability": $scope.Product.Changeability,
"CanGiveBack": $scope.Product.CanGiveBack,
"IsExist": $scope.Product.IsExist,
"BrandCode": 1,
"WarrantyCode": 1,
"MadeIn": $scope.Product.MadeIn,
"Description": $scope.Product.Description
};
var ProductAttrbiute =
{
"FramesColor": $scope.Product.FramesColor,
"FramesMaterial": $scope.Product.FramesMaterial,
"LensMaterial": $scope.Product.LensMaterial,
"LensColor": $scope.Product.LensColor,
"IsForMale": $scope.Product.IsForMale,
"IsSunny": $scope.Product.IsSunny
};
$.ajax({
url: '/Product/PostRegister',
type: 'POST',
contentType: "application/json",
dataType: "json",
data: '__RequestVerificationToken:'+token+","+JSON.stringify({ productRegisterVm: ProductRegisterVm, productAttrbiute: ProductAttrbiute }),
success: function (data) {
alert(data.success);
},
error: function() {
alert("ERROOOOOOOR");
}
});
你會得到什麼錯誤? –
請僅爲您的字符串使用英文 –
我的錯誤是: 所需的防僞表單字段__RequestVerificationToken不存在 –