我正在尝试从我的数据库中获取事件并用这些事件填充完整日历。事件没有显示。虽然当我在我的控制器中创建用于测试的事件时,它们正在显示
控制器:在这种情况下没有显示事件
public JsonResult getEvents()
{
UserProfile user = getUserProfile();
List<Calendar> events = db.Calendars.Where(c => c.userID == user.userID).ToList();
IList<calendarPost> tasksList = new List<calendarPost>();
foreach (Calendar eve in events)
{
tasksList.Add(new calendarPost
{
id = eve.recordID,
title = eve.recordDescription,
start = ToUnixTimespan(eve.startTime),
end = ToUnixTimespan(eve.endTime),
url = "www.google.com"
// });
// }
});
}
return Json(tasksList.ToArray(), JsonRequestBehavior.AllowGet);
如果我这样做,事件将在哪里显示:
public JsonResult getEvents()
{
UserProfile user = getUserProfile();
List<Calendar> events = db.Calendars.Where(c => c.userID == user.userID).ToList();
IList<calendarPost> tasksList = new List<calendarPost>();
// foreach (Calendar eve in events)
// {
tasksList.Add(new calendarPost
{
id = 5,
title = "test",
start = ToUnixTimespan(DateTime.Now.AddHours(1)),
end = ToUnixTimespan(DateTime.Now.AddHours(2)),
url = "www.google.com"
// });
// }
});
return Json(tasksList.ToArray() , JsonRequestBehavior.AllowGet);
}
是的,顺便说一句,两者都产生相同的 Json 输出
[{"id":5,"title":"test","start":1336945877,"end":1336949477,"url":"www.google.com","backgroundColor":null}]
[{"id":1,"title":"Testing the Calendar","start":1349384400,"end":1352062800,"url":"www.google.com","backgroundColor":null},{"id":3,"title":"Testing Votes","start":1325748600,"end":1325752200,"url":"www.google.com","backgroundColor":null}]