我已经实施了完整的日历。它确实按预期显示,但获取数据出错
.cshtml
<div id='calendar'></div>
.cshtml.cs
public class IndexModel : PageModel
{
public JsonResult OnPost(DateTime start, DateTime end)
{
return new JsonResult(new
{
url = "something",
title = "something else",
start = ConvertToUnixTimestamp(DateTime.Now).ToString(),
end = ConvertToUnixTimestamp(DateTime.Now.AddDays(2)).ToString(),
allDay = false,
backgroundColor = "red",
textColor = "green"
});
}
}
.js
document.addEventListener('DOMContentLoaded', function () {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
events: {
url: '/Overview/Employee/Index',
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
method: 'POST'
},
plugins: ['dayGrid']
});
calendar.render();
});
当我加载页面时,我看到一个请求正在发生,但它返回一个 400 错误请求。知道为什么吗?
请求: