I am getting a javascript error when I am trying to load scheduler events from my MVC controller, causing the calendar to display empty. The error is 0x800a138f - JavaScript runtime error: Unable to get property ‘valueOf’ of undefined or null reference at line 193, column 472 of dhtmlxscheduler.js. I have verified the date format being passed in the JSON and in case it was a default date format issue I added the statement to set the Config.api_date format to “%m/%d/%Y &H:%i:%s” (to represent my windows MM/dd/yyyy HH:mm:ss date format). Below is what my JSON looks like:
[{“id”:2094,“text”:“How to Choose a House”,“start_date”:“12/21/2015 00:00:00”,“end_date”:“12/21/2015 02:00:00”},{“id”:2092,“text”:“How to Choose a House”,“start_date”:“12/23/2015 00:00:00”,“end_date”:“12/23/2015 02:00:00”},{“id”:2096,“text”:“How to Choose a House”,“start_date”:“12/24/2015 00:00:00”,“end_date”:“12/24/2015 02:00:00”},{“id”:2097,“text”:“How to Choose a House”,“start_date”:“12/30/2015 00:00:00”,“end_date”:“12/30/2015 02:00:00”},{“id”:2095,“text”:“How to Choose a House”,“start_date”:“12/30/2015 00:00:00”,“end_date”:“12/30/2015 02:00:00”}]
My server-side init code is below:
public ActionResult ShowCalendar()
{
var scheduler = new DHXScheduler(this);
scheduler.Skin = DHXScheduler.Skins.Flat;
scheduler.InitialView = "month";
scheduler.Config.api_date = "%m/%d/%Y &H:%i:%s";
scheduler.LoadData = true;// allows loading data
return View(scheduler);
}
public ContentResult Data()
{
// Database first stored proc to return course list - I know I can probably
// use aliases in data annotations and use this directly but am iterating it for now,
// making sure my JSON object has the correct field names.
List<blsp_GetCurrentCoursesScheduled_Result> CurrentScheduledCourses = db.blsp_GetCurrentCoursesScheduled().ToList();
List<CourseCalendarEvent> ScheduledCourses = new List<CourseCalendarEvent>();
foreach (blsp_GetCurrentCoursesScheduled_Result ScheduledCourse in CurrentScheduledCourses)
{
CourseCalendarEvent newCourse = new CourseCalendarEvent();
newCourse.id = ScheduledCourse.CourseScheduleID;
newCourse.text = ScheduledCourse.SessionName;
newCourse.start_date = ScheduledCourse.StartDate.ToString("MM/dd/yyyy HH:mm:ss");
int CourseHours = 2;
newCourse.end_date = ScheduledCourse.StartDate.AddHours(CourseHours).ToString("MM/dd/yyyy HH:mm:ss");
ScheduledCourses.Add(newCourse);
}
string myJson = JsonConvert.SerializeObject(ScheduledCourses);
return new SchedulerAjaxData(myJson);
}
My ScheduledCourses class looks like the following:
public class CourseCalendarEvent
{
public int id = 0;
public string text = “”;
public string start_date = “”;
public string end_date = “”;
}
Been beating my head against the wall for several hours now and hoping someone can point out what I am doing wrong. Thanks in advance!