In a asp.net core application I have following code:
“`
$(‘.DepartmentDelete’).click(function (event) {
var r = confirm(‘Warning you are about to delete a record!’);
if (r === true) {
var id = $(this).attr(‘data-Id’);
var Depid = $(this).attr(‘data-DepId’);
var theDatestr = $(this).attr(‘data-datum’);
console.log(‘theDatestr: ‘ + theDatestr);
var datum = parseDate(theDatestr);
console.log(‘ datum: ‘ + datum);
$.ajax({
type: “post”,
url: ‘/RoosterMember/SetDepartment?handler=Delete’,
contentType: “application/json; charset=utf-8”,
dataType: “json”,
beforeSend: function (xhr) {
xhr.setRequestHeader(“X-XSRF-TOKEN”,
$(‘input:hidden[name=”__RequestVerificationToken”]’).val());
},
data: JSON.stringify({
UserId: id,
DepartmentId: Depid,
StartDate: datum
})
}).done(function (message) {
alert(message);
window.location.reload(true);
});
}
});
When I run this I get following in my console window:
“`
theDatestr: 30-11-2021
datum: Tue Nov 30 2021 00:00:00 GMT+0100 (Central European Standard Time)
But then when I look into the Network window I see:
StartDate: “2021-11-**29
so one day is subtracted from the Date!!
(with any date I use it subtracts always one day)
Also the receiving serverside routine is receiving this false date.
I am banging my head against the wall what I am doing wrong, especially because I am using this same routine on several slight different occasions without problems.