Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Put field __RequestVerificationToken along with JSON data in ajax script

$
0
0

I have an ajax script which calls method with following parameters.

    [HttpPost]
    [Authorize(Roles ="Klient")]
    [ValidateAntiForgeryToken]
    public ActionResult ChangeHouseParticipants(string houseName, List<Participant> participants)
    {
         return View();
    }

This script presents in that way.

for (var i = 0; i < list.length; i+=3) {
    	jsonArray.push({ Name: list[i].value, Surname: list[i+1].value, BirthDate: list[i+2].value });
        }
    var data = JSON.stringify({
    	houseName: $('select[name="SelectedHousesParticipants"]').val(),
    	participants: jsonArray,
    });$.ajax({
    	type: "POST",
    	url: "/ClientReservations/ChangeHouseParticipants",
    	data: data,
    	headers: {
    		'__RequestVerificationToken': $("[name='__RequestVerificationToken']").val()
    	},
    	contentType: "application/json; charset=utf-8",
    	success: function (response) {$('assignedParticipants').html(response)
    	},
    	}
    });

I thought that adding field with token into headers section would solve the issuse. But I still got the message that__RequestVerificationToken is not present. Any proposals, How to solve it?


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>