Kendo 调度程序 - 事件未显示
Kendo Scheduler - Event not showing
我试图在 Kendo 调度程序中显示事件,但它不起作用。我认为这是因为来自服务器的 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"
}]
@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" };
}
我试图在 Kendo 调度程序中显示事件,但它不起作用。我认为这是因为来自服务器的 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"
}]
@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" };
}