Hi @JROW ,
The Razor Pages are automatically protected from XSRF/CSRF. This is the reason why you get the 400 error. You should set the XSRF-TOKEN when you want to use the ajax to send request in razor page.
More details, you could refer to below codes:
1.If you are using the asp.net core6, please add below codes into the program.cs
builder.Services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
2.If you are using the asp.net core 5, please add below codes into the startup.cs:
services.AddAntiforgery(o => o.HeaderName = "XSRF-TOKEN");
3.Add below codes into the razor pages
@Html.AntiForgeryToken()
4.Modify the ajax codes:
$.ajax({
type: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: routeUrl + "?handler=AddTimesheet",
data: requestData,
success: function (data) {
console.log(data)
calendar.refetchEvents();
onCloseModal();
}
});