Problem showing data for Scheduler on .Net 6

1 Answer 237 Views
Scheduler
Diego
Top achievements
Rank 1
Diego asked on 25 Oct 2022, 07:00 AM

Hi,

I have been working with the Scheduler and I can't make it to work.

I have an object that extends ISchedulerEvent with the start and end dates, apart from all the needed parameters:

public class BsScheduleMeeting : ISchedulerEvent
    {
        private DateTime start;
        public DateTime Start
        {
            get
            {
                return start;
            }
            set
            {
                start = value.ToUniversalTime();
            }
        }

        private DateTime end;
        public DateTime End
        {
            get
            {
                return end;
            }
            set
            {
                end = value.ToUniversalTime();
            }
        }

    }

With this we created a scheduler on a Razor view with a custom datasource, defining the model and the transport functionality (is only a read):

    @(Html.Kendo().Scheduler<BsScheduleMeeting>()
        .Name("scheduler")
        .Date(DateTime.Now.Date)
        .StartTime(DateTime.Now.Date.AddHours(7))
        .EndTime(DateTime.Now.Date.AddHours(22))
        .Editable(false)
        .Height(700)
        .Views(views =>
        {
            views.DayView(day => day.Selected(true));
        })
        .Timezone("Etc/UTC")
        .DataSource(datasource => datasource
            .Custom()
            .Schema(schema => schema    
                .Model(m => {
                    m.Id(f => f.MeetingID);
                    m.Field("title", typeof(string)).DefaultValue("No title").From("title");
                    m.Field("start", typeof(DateTime)).From("start");
                    m.Field("end", typeof(DateTime)).From("end");
                    m.Field("description", typeof(string)).From("description");
                    m.Field("recurrenceID", typeof(int)).From("recurrenceID");
                    m.Field("recurrenceRule", typeof(string)).From("recurrenceRule");
                    m.Field("recurrenceException", typeof(string)).From("recurrenceException");
                    m.Field("isAllDay", typeof(bool)).From("isAllDay");
                    m.Field("startTimezone", typeof(string)).From("startTimezone");
                    m.Field("endTimezone", typeof(string)).From("endTimezone");
                })
            )
            .ServerPaging(false)
            .ServerFiltering(true)
            .Transport(transport => transport
                .Read(read =>
                {
                    read.Action("GetJson", "BSSchedule");
                })
            )
        )
    )

The controller call that returns the data is the next one:

public virtual JsonResult GetJson([DataSourceRequest] DataSourceRequest request)
        {
            return Json(GetTasks().ToDataSourceResult(request));
        }

        private IList<BsScheduleMeeting> GetTasks()
        {
            IList<BsScheduleMeeting> schedulerTasks = new List<BsScheduleMeeting>()
            {
                new BsScheduleMeeting {
                    Description = "",
                    StartTimezone = "UTC",
                    MeetingID = 1,
                    Title = "AP Physics",
                    Start = new DateTime(2022,10,24,8,00,00),
                    End= new DateTime(2022,10,24,9,00,00),
                    EndTimezone = "UTC",
                    RecurrenceRule = null,
                    RecurrenceID = 1,
                    RecurrenceException = null,
                    IsAllDay = false
                },
                new BsScheduleMeeting {
                    Description = "",
                    StartTimezone = "UTC",
                    MeetingID = 2,
                    Title = "History",
                    Start = new DateTime(2022,10,24,9,00,00),
                    End= new DateTime(2022,10,24,10,00,00),
                    EndTimezone = "UTC",
                    RecurrenceRule = null,
                    RecurrenceID = 2,
                    RecurrenceException = null,
                    IsAllDay = false
                },
                new BsScheduleMeeting {
                    Description = "",
                    StartTimezone = "UTC",
                    MeetingID = 3,
                    Title = "Art",
                    Start = new DateTime(2021,10,24,9,00,00),
                    End= new DateTime(2022,10,24,10,00,00),
                    EndTimezone = "UTC",
                    RecurrenceRule = null,
                    RecurrenceID = 3,
                    RecurrenceException = null,
                    IsAllDay = false
                },
            };

            return schedulerTasks.ToList();
        }

With this, I tryed everything but couldn't make it work. The most common error that I get is this one on Javascript:

and the data is being returned correctly, as shown in the next image:

What can I do so the Scheduler gets the info that I send?

Thank you in advance,

Diego.

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 27 Oct 2022, 11:09 AM

Hello Diego,

Thank you for the shared code snippets.

I examined them and would recommend the following:

  • Update the From() methods in Model configuration - the field names should match the Model property names:
            .Schema(schema => schema
                .Model(m =>
                {
                    m.Id(f => f.MeetingID);
                    m.Field("title", typeof(string)).DefaultValue("No title").From("Title");
                    m.Field("start", typeof(DateTime)).From("Start");
                    m.Field("end", typeof(DateTime)).From("End");
                    m.Field("description", typeof(string)).From("Description");
                    m.Field("recurrenceID", typeof(int)).From("RecurrenceID");
                    m.Field("recurrenceRule", typeof(string)).From("RecurrenceRule");
                    m.Field("recurrenceException", typeof(string)).From("RecurrenceException");
                    m.Field("isAllDay", typeof(bool)).From("IsAllDay");
                    m.Field("startTimezone", typeof(string)).From("StartTimezone");
                    m.Field("endTimezone", typeof(string)).From("EndTimezone");
                }))
  • Ensure that the JSON Serialization is configured in the Program.cs file, as described in the article below:

https://docs.telerik.com/aspnet-core/installation/json-serialization

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages()
               .AddJsonOptions(options =>
                options.JsonSerializerOptions.PropertyNamingPolicy = null);

// Add Kendo UI services to the services container"
builder.Services.AddKendo();

var app = builder.Build();
...

Would you please apply these modifications and let me know if the events are loaded as expected at your end?

 

Regards, Mihaela Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Diego
Top achievements
Rank 1
commented on 28 Oct 2022, 01:36 PM

Hi Mihaela,

We just tryed what you said and it is working now. 

Thank you so much,

Diego

Tags
Scheduler
Asked by
Diego
Top achievements
Rank 1
Answers by
Mihaela
Telerik team
Share this question
or