Kendo Scheduler - 事件未显示

时间:2016-02-19 14:48:26

标签: javascript json kendo-ui kendo-asp.net-mvc kendo-scheduler

我正在尝试在Kendo Scheduler中显示事件,但它无效。我认为这是因为来自服务器的JSON日期格式格式不正确。任何帮助表示赞赏。

@(Html.Kendo().Scheduler<TaskViewModel>()
.Name("Scheduler")
.Date(DateTime.Today)
.Views(views =>
{
    views.DayView();
    views.WeekView();
    views.MonthView();
})
.Timezone("Etc/UTC")
.DataSource(d => d
    .Model(m =>
    {
        m.Field(f => f.Title);
        m.Field(f => f.Start);
        m.Field(f => f.End);
        m.Field(f => f.IsAllDay); 
    })
.Read(read => read.Action("GetScheduleEvent", "DataSource"))
)
)

JSON回复

[{"RecurrenceRule":null,
  "RecurrenceException":null,
  "IsAllDay":true,
  "Start":"\/Date(1455775200000)\/",
  "StartTimezone":null,
  "End":"\/Date(1456034400000)\/",
  "EndTimezone":null,
  "Title":"Test Event"
}]

1 个答案:

答案 0 :(得分:1)

@Ram:日期格式没有问题。您的JSON响应格式不正确。它应该采用这种格式

{"Data":[],"Total":55,"AggregateResults":null,"Errors":null}

我的猜测是你可能忘记调用ToDataSourceResult方法,如下所示

public virtual JsonResult Read([DataSourceRequest] DataSourceRequest request)
        {
            return Json(taskService.GetAll().ToDataSourceResult(request));
        }

我在JSON响应的帮助下创建了原始JsonData。下面是我用于测试的代码片段,它正在运行。希望这可以帮助你!!

public ContentResult GetScheduleEvent([DataSourceRequest] DataSourceRequest request)
        {
            //string jsonString = "{\"Data\":[{\"RecurrenceRule\":null, \"RecurrenceException\":null,  \"IsAllDay\":false,  \"Start\":\"Sat Feb 20 2016 01:17:07 GMT-0700 (PDT)\",  \"StartTimezone\":null,  \"End\":\"Sat Feb 20 2016 04:17:07 GMT-0700 (PDT)\",  \"EndTimezone\":null,  \"Title\":\"Test Event\"}],\"Total\":1,\"AggregateResults\":null,\"Errors\":null}";
            string jsonString = "{\"Data\":[{\"RecurrenceRule\":null, \"RecurrenceException\":null,  \"IsAllDay\":true,  \"Start\":\"\\/Date(1455775200000)\\/\",  \"StartTimezone\":null,  \"End\":\"\\/Date(1456034400000)\\/\",  \"EndTimezone\":null,  \"Title\":\"Test Event\"}],\"Total\":1,\"AggregateResults\":null,\"Errors\":null}";
            return new ContentResult { Content = jsonString, ContentType = "application/json" };
        }