Unable to bind data to Kendo Scheduler

眉间皱痕 提交于 2019-12-02 08:09:18

问题


I've got this Kendo Scheduler that is displayed in the View but without any data.

The Scheduler on the View:

@(Html.Kendo().Scheduler<ProjName.Models.ScheduleInspectionModel>()
    .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("ControllerName", "GetScheduleInspections")
    )
)

The datasource invokes the controller method below:

public ActionResult GetScheduleInspections([DataSourceRequest]DataSourceRequest request)
{
    ScheduleInspectionModel sim = new ScheduleInspectionModel();
    var gsio = sim.getScheduleInspections();

    List<ScheduleInspectionModel> list = new List<ScheduleInspectionModel>();

    if (gsio.scheduleinspections != null)
    {
        foreach (wsScheduleInspection.scheduleInspectionOutput scheduleInspection in gsio.scheduleinspections)
        {
            ScheduleInspectionModel sim2 = new ScheduleInspectionModel
            {
                GlobalEquipConditionId = scheduleInspection.globalEquipmentCondition.id,
                Description = scheduleInspection.globalEquipmentCondition.code,
                Start = DateTime.Now,
                End = DateTime.Now.AddHours(2),
                Title = scheduleInspection.globalEquipmentCondition.code,
                IsAllDay = true

            };

            list.Add(sim2);
        }
    }
    return Json(list.ToDataSourceResult(request));
}

But this method is never run, despite being on the Scheduler Datasource property. It should run that method and return a list of inspections. I don't know why isn't the method being hit. With a Kendo Grid, for example, the method on the Datasource Read is hit as soon as the page is loaded.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/27228036/unable-to-bind-data-to-kendo-scheduler

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