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

查看:125
本文介绍了无法将数据绑定到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));
}

但是,尽管此方法位于Scheduler Datasource属性上,但它永远不会运行.它应该运行该方法并返回检查清单.我不知道为什么该方法没有被使用.例如,使用Kendo网格,页面加载后立即点击数据源读取"上的方法.

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天全站免登陆