You need to write the
{
url: 'api/events/get/byrange',
data: {
id: typeof($scope.calendar) == 'undefined' ? '1' : '2'
}
};
Without setting it in a variable var eventSource
. Instead just append that piece of code inside your FullCalendar initialization.
However, i don't use this method. Instead I perform a JSON request to an action which returns a list of objects.
Javascript:
$.getJSON('GetCalendar?TrainingId=' + $('#TrainingId').val(), function (response) {
$('#CalendarWrapper').empty();
$('#CalendarWrapper').append("<div id='calendar' name='calendar'></div>");
window.events = response;
window.calendar = $('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay' //, basicWeek,basicDay
},
selectHelper: true,
allDaySlot: false,
slotDuration: '00:15:00',
buttonIcons: true, // show the prev/next text
weekNumbers: false,
editable: true,
selectOverlap: true,
unselectAuto: true,
eventLimit: true, // allow "more" link when too many events
lang: GetFullCalendarLanguage(),
aspectRatio: 2.5,
events: window.events,
});
_CalendarBuild = true;
})
Action:
[HttpGet]
public JsonResult GetCalendar(int TrainingId)
{
var model = QUERY
.Select(x => new FullCalendar
{
title = x.Module.Description + ", " + x.Local.Info,
Day = x.Day,
(...)
})
.ToList();
return Json(model, JsonRequestBehavior.AllowGet);
}
FullCalendar:
public class FullCalendar
{
public virtual string title { get; set; }
public virtual string url { get; set; }
public virtual DateTime Day { get; set; }
public virtual string start { get; set; }
public virtual string end { get; set; }
public virtual bool startEditable { get; set; }
}
And when I want to render again I just call the javascript again (that's placed inside a function).