我正在尝试使用FullCalendar,它显示得很好,并带有来自数据库和谷歌日历的提要更新事件。
但是我的问题是如何在页面上有一个保存按钮,当按下该按钮时,我可以将日历中的所有事件传回我的控制器,以便我可以将它们保存到数据库中?
一些代码(查看):
$(document).ready(function () {
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events div.external-event').each(function () {
// create an Event Object (http://arshaw.com/fullcalendar/docs/event_data/Event_Object/)
// it doesn't need to have a start or end
var eventObject = {
title: $.trim($(this).text()) // use the element's text as the event title
};
// store the Event Object in the DOM element so we can get to it later
$(this).data('eventObject', eventObject);
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
// -------- Calendar set up ...
$('#calendar').fullCalendar({
eventSources:
[
{ // Uk holidays
url: 'http://www.google.com/calendar/feeds/uk__en%40holiday.calendar.google.com/public/basic',
color: 'blue',
textColor: 'white'
},
{ // booked availability
url: '/avalibility/GetAvail',
color: 'red'
}
],
//... more set up
});
控制器代码:
public JsonResult GetAvail(double start, double end)
{
var startDateTime = FromUnixTimestamp(start);
var endDateTime = FromUnixTimestamp(end);
var events = from e in db.PROJECT_CALENDAR
select e;
var AvilList = new List<object>();
foreach (var e in events)
{
AvilList.Add(
new
{
id = e.ID,
title = e.Title,
description = e.Title,
start = e.DateStart,
end = e.DateEnd
});
}
return Json(AvilList.ToArray(), JsonRequestBehavior.AllowGet);
}