We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Javascript error when trying to return data for a schedule


I have this error when trying to return data for a schedule: "Uncaught TypeError: Cannot read property 'StartTime' of undefined" in ej.web.all.min.js.

My controller action looks like this:

public JsonResult Batch(EditParams param)
            var data = new List<ScheduleData>();
            data.Add(new ScheduleData() { Subject = "Testing", StartTime = DateTime.Now, EndTime = DateTime.Now.AddDays(3), AllDay = true, Owner = 1 });
            return Json(data.AsEnumerable(), JsonRequestBehavior.AllowGet);

The class ScheduleData looks like this:

public class ScheduleData
        public int Id;

        public string Subject;

        public string Location;

        public System.DateTime StartTime;

        public System.DateTime EndTime;

        public string Description;

        public System.Nullable<int> Owner;

        public System.Nullable<int> Priority;

        public System.Nullable<byte> Recurrence;
        public string Categorize;
        public System.Nullable<bool> AllDay;        

And the Schedule code is this:

    .Resources(res => { res.Field("OwnerId").Title("Owner").Name("Owners").AllowMultiple(true).ResourceSettings(flds => flds.Datasource((IEnumerable<object>)ViewBag.Owners).Text("text").Id("id").Color("color")).Add(); })
    .Group(gr => { gr.Resources(ViewBag.Resources); })
    //.AppointmentSettings(fields => fields.Datasource(ViewBag.datasource)
    .AppointmentSettings(fields => fields.Datasource(ds => ds.URL("/Projects/GetData").CrudURL("/Projects/Batch"))

The error comes after I try to insert a new appoitment, so after the return from the Batch action.

Thank you!

1 Reply

KK Karthigeyan Krishnamurthi Syncfusion Team February 13, 2017 06:05 AM UTC

Hi Cornel,   
Thank you for contacting Syncfusion Support.   
We suspect that appointment was not saved properly in database, which could have caused the issue. We have prepared a CRUD sample with the provided code example, which can be downloaded from:   
In the above sample, when an appointment is added/edited/deleted, it will be reflected in the database too. Kindly refer to the below code example used in the sample.   
public JsonResult Batch(EditParams param) 
            if (param.action == "insert" || (param.action == "batch" && param.added != null))          // this block of code will execute while inserting the appointments 
            if (param.action == "remove" || param.deleted != null)                                        // this block of code will execute while removing the appointment 
            if ((param.action == "batch" && param.changed != null) || param.action == "update")   // this block of code will execute while updating the appointment 
            IEnumerable data = new DataClasses1DataContext().ScheduleDatas.Take(500); // nw.Appointment.Take(5); 
            return Json(data, JsonRequestBehavior.AllowGet); 

Live Chat Icon For mobile
Up arrow icon