Unable to bind data to Kendo Scheduler

匆匆过客 提交于 2019-12-02 03:40:10

Try making sure your definition has these two items as I think they are required.

.Date(new DateTime(2013, 6, 13))
.StartTime(new DateTime(2013, 6, 13, 7, 00, 00))

EDIT

I was able to get the following code to work:

Model

// NOTE: It's important that your model class implements ISchedulerEvent
public class TaskViewModel : ISchedulerEvent
{
    public string Title { get; set; }
    public string Description { get; set; }
    public bool IsAllDay { get; set; }
    public DateTime Start { get; set; }
    public DateTime End { get; set; }
    public string StartTimezone { get; set; }
    public string EndTimezone { get; set; }
    public string RecurrenceRule { get; set; }
    public string RecurrenceException { get; set; }
}

SchedulerController.cs

public class SchedulerController : Controller
{
    // GET: Scheduler
    public ActionResult Index()
    {
        var model = new SchedulerViewModel();

        // In this case, it doesn't matter what this model is really since we're using AJAX binding
        return View(model);
    }

    // I usually have my binding methods for Kendo use HttpPost
    [HttpPost]
    public ActionResult GetData([DataSourceRequest] DataSourceRequest request)
    {
        var data = new List<TaskViewModel>
            {
                new TaskViewModel
                    {
                        Start = new DateTime(2014, 12, 1, 8, 0, 0),
                        End = new DateTime(2014, 12, 1, 17, 0, 0),
                        Title = "Task 1"
                    }
            };

        return Json(data.ToDataSourceResult(request));
    }
}

Index.cshtml (view)

@(Html.Kendo().Scheduler<TaskViewModel>()
    .Name("scheduler")
    .Views(views =>
    {
        views.DayView();
        views.WorkWeekView();
        views.WeekView();
        views.MonthView(mv => mv.Selected(true));
        views.AgendaView();
    })
    .Timezone("Etc/UTC")
    .DataSource(d => d
        .Read("GetData", "Scheduler")
    ))

If this doesn't work for you, I would make sure your versions (for Kendo, jQuery, etc) are correct. Hope this helps.

Yes, Scheduler read is called as soon as it is loeded. But it may not be getting data in proper format as it expects. So it is not able to bind the data. If you can check for these modification:

1) Define the "Model" in "DataSource" of scheduler as defined in this example.

2) Also the action method should return object of "MyModel" class(model on which scheduler is defined)
not "ScheduleInspectionModel" class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!