无法将数据绑定到 Kendo Scheduler [英] Unable to bind data to Kendo Scheduler

查看:14
本文介绍了无法将数据绑定到 Kendo Scheduler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个显示在视图中但没有任何数据的 Kendo Scheduler.

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

视图上的调度程序:

@(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));
}

但是这个方法永远不会运行,尽管它位于调度程序数据源属性上.它应该运行该方法并返回检查列表.我不知道为什么方法没有被击中.以 Kendo Grid 为例,页面加载后立即命中 Datasource Read 上的方法.

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.

推荐答案

尝试确保您的定义包含这两个项目,因为我认为它们是必需的.

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))

编辑

我能够使以下代码工作:

I was able to get the following code to work:

模型

// 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(查看)

@(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")
    ))

如果这对您不起作用,我会确保您的版本(对于 Kendo、jQuery 等)是正确的.希望这会有所帮助.

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

这篇关于无法将数据绑定到 Kendo Scheduler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆