无法使用 JSON 呈现事件全日历



我正在使用FullCalendar ver 3.9.0。我有一个问题。这些事件不会在 MVC 中呈现 JsonResult 的结果。我通过javascript检查了它:$('#calendar').fullCalendar('clientEvents');它没有返回长度。但是当我使用$.ajax时,它会返回两个数组,如下所示:[{"id":5275,"title":"Test Image","start":"23/08/2018 16:39:47","end":"26/08/2018 16:39:47","backgroundColor":"#17a2b8"},{"id":5276,"title":"Test video","start":"23/08/2018 16:39:47","end":"26/08/2018 16:39:47","backgroundColor":"#17a2b8"}]

FullCalendar的配置:

$('#calendar').fullCalendar({
defaultView: 'basicWeek',
themeSystem: 'bootstrap4',
editable: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay,listWeek'
},
events: {
url: '/Schedule/TrinhChieuSchedule',
type: 'POST',
data: model
},
success: function(data) {
console.log(data);
},
error: function(err) {
AlertMessageDefaultPosition(err, "warning");
console.log(err);
},
});

这是 MVC 中的 JsonResult:

public JsonResult TrinhChieuSchedule(ScheduleJsonModel model)
{
DateTime? ngayBatDau = null;
DateTime? ngayKetThuc = null;
if (!String.IsNullOrEmpty(model.ngayBatDau))
ngayBatDau = DateTime.Parse(model.ngayBatDau);
if (!String.IsNullOrEmpty(model.ngayKetThuc))
ngayKetThuc = DateTime.Parse(model.ngayKetThuc);
var list = db.SPC_SP_TrinhChieuSchedule(model.madv, ngayBatDau, ngayKetThuc);
var serializer = new JavaScriptSerializer();
var jsonString = serializer.Serialize(list.ToArray());
return Json(jsonString);
}

我已经找到了解决这个问题的方法。只需将日期格式更改为完整日历标准"YYYY-MM-DDThh:mm:ss"

最新更新