Edit Params are null

I'm getting null edit parameter objects when I do an edit of an appointment in Scheduler.  I tried removing the [Key] attribute on the Schedule object like I've seen recommended on this forum before, but I got the same results.  The 'value' property is populated with 'UpdateData' but everything else is null.

Schedule.cs
    public class Schedule : ModelBase
    {
        [Key]
        public int ScheduleID { get; set; }
        public int Id { get { return ScheduleID; } }

        [Display(Name = "Route")]
        public int RouteID { get; set; }
        public virtual Route Route { get; set; }

        [Display(Name = "User")]
        public string UserID { get; set; }
        public virtual User User { get; set; }

        public string Subject { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public string StartTimezone { get; set; }
        public string EndTimezone { get; set; }
        public bool IsAllDay { get; set; }
        public string RecurrenceRule { get; set; }
        public string RecurrenceID { get; set; }
        public string RecurrenceException { get; set; }
    }

SchedulesController.cs - UpdateData method
        [HttpPost]
        public JsonResult UpdateData(EditParams param)
        {
            if (param.action == "insert" || (param.action == "batch" && param.added != null)) // this block of code will execute while inserting the appointments
            {
                var value = (param.action == "insert") ? param.value : param.added[0];
                int intMax = _context.Schedule.Select(x => x.ScheduleID).DefaultIfEmpty(0).Max();
                DateTime startTime = Convert.ToDateTime(value.StartTime);
                DateTime endTime = Convert.ToDateTime(value.EndTime);
                Schedule appointment = new Schedule()
                {
                    ScheduleID = intMax + 1,
                    StartTime = startTime,
                    EndTime = endTime,
                    Subject = value.Subject,
                    IsAllDay = value.IsAllDay,
                    StartTimezone = value.StartTimezone,
                    EndTimezone = value.EndTimezone,
                    RecurrenceRule = value.RecurrenceRule,
                    RecurrenceID = value.RecurrenceID,
                    RecurrenceException = value.RecurrenceException
                };
                _context.Schedule.Add(appointment);
                _context.SaveChanges();
            }
            if (param.action == "UpdateData" || (param.action == "Batch" && param.changed != null)) // this block of code will execute while updating the appointment
            {
                var value = (param.action == "UpdateData") ? param.value : param.changed[0];
                var filterData = _context.Schedule.Where(c => c.ScheduleID == Convert.ToInt32(value.ScheduleID));
                if (filterData.Count() > 0)
                {
                    DateTime startTime = Convert.ToDateTime(value.StartTime);
                    DateTime endTime = Convert.ToDateTime(value.EndTime);
                    Schedule appointment = _context.Schedule.Single(A => A.ScheduleID == Convert.ToInt32(value.Id));
                    appointment.StartTime = startTime;
                    appointment.EndTime = endTime;
                    appointment.StartTimezone = value.StartTimezone;
                    appointment.EndTimezone = value.EndTimezone;
                    appointment.Subject = value.Subject;
                    appointment.IsAllDay = value.IsAllDay;
                    appointment.RecurrenceRule = value.RecurrenceRule;
                    appointment.RecurrenceID = value.RecurrenceID;
                    appointment.RecurrenceException = value.RecurrenceException;
                }
                _context.SaveChanges();
            }
            if (param.action == "remove" || (param.action == "batch" && param.deleted != null)) // this block of code will execute while removing the appointment
            {
                if (param.action == "remove")
                {
                    int key = Convert.ToInt32(param.key);
                    Schedule appointment = _context.Schedule.Where(c => c.ScheduleID == key).FirstOrDefault();
                    if (appointment != null) _context.Schedule.Remove(appointment);
                }
                else
                {
                    foreach (var apps in param.deleted)
                    {
                        Schedule appointment = _context.Schedule.Where(c => c.ScheduleID == apps.ScheduleID).FirstOrDefault();
                        if (apps != null) _context.Schedule.Remove(appointment);
                    }
                }
                _context.SaveChanges();
            }
            var data = _context.Schedule.ToList();
            return Json(data);
        }

SchedulesController.cs - EditParams class
    public class EditParams
    {
        public string key { get; set; }
        public string action { get; set; }
        public List<Schedule> added { get; set; }
        public List<Schedule> changed { get; set; }
        public List<Schedule> deleted { get; set; }
        public Schedule value { get; set; }
    }

Index.cshtml
@using Syncfusion.EJ2
@model IEnumerable<DotNetCoreSqlDb.Models.Schedule>

@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
    var dataManager = new DataManager()
    {
        Url = "Schedules/LoadData",
        Adaptor = "UrlAdaptor",
        CrudUrl = "Schedules/UpdateData",
        CrossDomain = true
    };
}

<div class="row">
    <ejs-schedule id="schedule" height="550" selectedDate="new DateTime(2019, 8, 2)">
        <e-schedule-eventsettings dataSource="dataManager">
        </e-schedule-eventsettings>
    </ejs-schedule>
</div>


2 Replies

BS Brad Shannon August 2, 2019 06:53 PM UTC

I found the fix in this thread: https://www.syncfusion.com/forums/143650/crud-operations-not-working

This...

public JsonResult UpdateData(EditParams param)

Should be this...

public JsonResult UpdateData([FromBody]EditParams param)


KK Karthigeyan Krishnamurthi Syncfusion Team August 5, 2019 05:52 AM UTC

Hi Brad, 

Syncfusion greetings. 

Yes, that is the correct way and we're glad you discovered it yourself. 

Regards, 
Karthi 


Loader.
Up arrow icon