Kendo Calendar DataSource not getting data from controller

1 Answer 92 Views
Scheduler
Jerry
Top achievements
Rank 1
Iron
Iron
Iron
Jerry asked on 21 Oct 2022, 06:58 PM

We are using Kendo-Scheduler in an Asp.net application.

We are having a problem getting events to display in the calendar.

When we use Server Binding, we can see the events display in the calendar as expected. We do the following in our ViewComponent:

public async Task<IViewComponentResult> InvokeAsync()

   {
   List<TaskViewModel> myTasks = GetItems();
   return View(myTasks);   //these events display on the calendar successfully
   }

However, we need to use Ajax Binding. When we do the following, no data is returned to the DataSource. When we look at scheduler_dataBound() for the data, we can see that no data is returned from the controller. Also the _total = 0

What am I doing wrong in the below? Why is the Server binding working but not the Ajax Binding?

 //my.cshtml
    @(Html.Kendo().Scheduler<MyApp.Core.ViewModels.TaskViewModel>()
    .Name("scheduler")
    .Date(new DateTime(2022, 10, 01))
    .StartTime(new DateTime(2022, 10, 01, 7, 00, 00))
    .Height(600)
    .Views(views =>
    {
        views.MonthView(m => {
            m.Selected(true);
            m.EventHeight(150);
        });
    })
    .Timezone("Etc/UTC")
    .DataSource(d => d
        .Model(m =>
        {
            m.Field(f => f.OwnerID).DefaultValue(1);
            m.Field(f => f.Title).DefaultValue("No title");
            m.Field(f => f.Description).DefaultValue("no desc");
            m.RecurrenceId(f => f.RecurrenceID);
        })
        .Read("Read", "MyController")
    )
    .Events(e => {
        e.DataBound("scheduler_dataBound");
    })
)
 <script type="text/javascript">
  function scheduler_dataBound(e) {
        var data = $("#scheduler").data("kendoScheduler").dataSource;
        console.log(data);      //Here -> _total=0 and _data has no objects
    }
  </script>


  //My Controller method
  public virtual JsonResult Read([DataSourceRequest] DataSourceRequest request)
 {
     //This is getting called from calendar datasource read
     return Json(GetItems().ToDataSourceResult(request));   //Here I am mocking up data
  }

  //My Mock data
  public List<TaskViewModel> GetItems()
  {
    List<TaskViewModel> list = new List<TaskViewModel>();
    list.Add(new TaskViewModel
     {
       Title = "Event 1",
       Start = new DateTime(2022, 10, 1),
       End = new DateTime(2022, 10, 1),
       Description = "Description 1",
       IsAllDay = false,
       OwnerID = 1,
       TaskID = 1
      });
       ......More data
      return list;
  }

1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 26 Oct 2022, 08:37 AM

Hello Jerry,

I see you have the same question posted in another forum thread, where I have already replied:

How to get tasks to render in calendar using AJAX binding

Is suggestion in the other post not helpful? I would also like to note that we monitor all forums, so there is no need to post the same question in multiple locations.

Regards,
Aleksandar
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/.

Tags
Scheduler
Asked by
Jerry
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
Aleksandar
Telerik team
Share this question
or