2017-07-05 16 views
0

私は内部サーバーエラーを取得:ASP.NET MVC AJAX POST ValidateAntiForgeryToken

@using (Html.BeginForm("", "Manage", FormMethod.Post, new { role = "form"})) 
{ 
    @Html.AntiForgeryToken() 
} 
<script> 
function Like(id) { 
    var requestData = { 
     profileId: id, 
     __RequestVerificationToken: $('[name=__RequestVerificationToken]').val(), 
    }; 

    $.ajax({ 
     url: '/Manage/Like', 
     type: 'POST', 
     data: JSON.stringify(requestData), 
     dataType: "json", 
     contentType: 'application/json; charset=utf-8', 
     error: function (xhr) { alert('Error: ' + xhr.statusText); }, 
     success: function (result) {}, 
     async: true, 
     processData: false 
    }); 
} 
</script> 

コントローラー:

[HttpPost] 
[ValidateAntiForgeryToken] 
public ActionResult Like(string profileId) 
{ ... } 

私は削除する場合は[ValidateAntiForgeryToken]すべてが正常に動作しますが、私は失います敬具。内部サーバーのエラーを修正するにはどうすればよいですか?

私はフィドラーSyntaxView 2つのリクエスト参照: / 同様/管理{ "プロファイルID":13、 "__ RequestVerificationToken": "jH2ofYlcTiHl8lixW_ANEHOg5KgwRh5Xl43lQfGkDFh55jX-x5cmz4RfPtbDfu92oQsTM7zsop83ldfbxMdIIELYZ0kfByFcXjUp-5mwyKZcQzjXP2gy6qW0iQOtLsqaDjFSzoxnyqM2MD42CbItzw2"}

/ __RequestVerificationToken = MNiKOJHZg7BGaTNccOjrR2Obf_nPhKfcwIPZVBUl53G368n5euzB4y1htH47VKg3V3mHfxkjYZDz6iPepQ7jpeXGARtlj6vV74B8zQbp4by9JR4Rcz4sHANm3WHb6WAXaLcsnFvWJth_8c98XKda5w2

+0

「JSON.stringify」を削除します。 – Arman

答えて

1
管理

シムからこれを取る。ここの質問include antiforgerytoken in ajax post ASP.NET MVC

function Like(id) { 
var form = $('form'); 
var token = $('input[name="__RequestVerificationToken"]', form).val(); 
$.ajax({ 
    url: '/Manage/Like', 
    type: 'POST', 
    data: { __RequestVerificationToken: token, profileID: id }, 
    error: function (xhr) { alert('Error: ' + xhr.statusText); }, 
    success: function (result) {}, 
    async: true, 
    processData: false 
}); 
} 
関連する問題