无法用数据填充Kendo Scheduler

编程入门 行业动态 更新时间:2024-10-12 05:45:54
本文介绍了无法用数据填充Kendo Scheduler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

第一次使用MVC和Kendo Scheduler,我无法获得要显示在日历上的数据.我有以下型号

First time using MVC and Kendo Scheduler and I can't get the data to show on the Calendar. I have the below Model

public class Events : ISchedulerEvent { public int Id { get; set; } public string Description { get; set; } public DateTime End { get; set; } public string EndTimezone { get; set; } public bool IsAllDay { get; set; } public string RecurrenceException { get; set; } public string RecurrenceRule { get; set; } public DateTime Start { get; set; } public string StartTimezone { get; set; } public string Title { get; set; } }

我的控制器只是简单地创建此类的一个实例,并向其添加数据并按以下方式返回列表:

My Controller just simply creates an instance of this class and adds data to it and returns a list as so:

public ActionResult Index() { return View(GetAll()); } public List<Events> GetAll() { var p = new List<Events>(); p.Add(new Events { Id = 1, Title = "Board Meeting", Start = DateTime.Now, End = DateTime.Now.AddHours(2) }); return p; }

我的看法仅仅是这样:

@using Kendo.Mvc.UI; @(Html.Kendo().Scheduler<Optic.Models.Calendar.Events>() .Name("scheduler") .Date(new DateTime(2014, 1, 22)) .StartTime(new DateTime(2013, 6, 13, 07, 00, 00)) .EndTime(new DateTime(2013, 6, 13, 21, 00, 00)) .Editable(false) .Height(600) .Views(views => { views.DayView(); views.WeekView(); views.MonthView(month => month.Selected(true)); views.AgendaView(); }) .DataSource(d => d .Model(m => m.Id(f => f.Id)) ) .BindTo(Model) )

日历会加载并从一天切换到一个月等等,但是日历中不会填充任何数据.我检查了模型,它确实有数据.我缺少某些东西以便使数据显示在日历上吗?任何帮助将不胜感激.

The calendar loads and switching from day to month and so on works, but no data will populate in the calendar. I've checked the model and it does have data. Is there something I am missing in order to get the data to show on the calendar? Any help would be greatly appreciated.

推荐答案

实际上,我发现我做错了什么.在.DataSources(d => d ..等等等等的视图下,我需要添加.Read("GetAll","ControllerName").然后在Controller中,我需要添加带有Json(e .ToDataSourceResult(request),JsonRequestBehavior.AllGet);如下所示.我还需要删除Index操作结果中的代码.解决了这个问题.请参见以下更改:

Actually I figured it out what I was doing wrong. In the view under .DataSources(d => d.. blah blah blah, I needed to add a .Read("GetAll", "ControllerName"). In the Controller I then needed to add the Read Method with a Json(e.ToDataSourceResult(request), JsonRequestBehavior.AllGet); as shown below. I also needed to take out the code in the Index action result. Took care of the issue. See changes below:

查看

@using Kendo.Mvc.UI; @model List<Optic.Models.Scheduling.Events> @(Html.Kendo().Scheduler<Optic.Models.Scheduling.Events>() .Name("scheduler") .Date(new DateTime(2014, 1, 22)) .StartTime(new DateTime(2013, 6, 13, 07, 00, 00)) .EndTime(new DateTime(2013, 6, 13, 23, 00, 00)) .Editable(false) .Height(600) .Views(views => { views.DayView(); views.WeekView(week => week.Selected(true)); views.MonthView(); views.AgendaView(); }) .DataSource(d => d .Model(m => m.Id(f => f.Id)) .Read("GetAll", "Scheduling") ) .BindTo(Model) )

控制器

public class SchedulingController : Controller { // // GET: /Scheduling/ public ActionResult Index() { return View(); } public JsonResult GetAll([DataSourceRequest] DataSourceRequest request) { var e = new List<Events> { new Events { Id =1, Title="Testing 1", Start= DateTime.Now.AddHours(1), End = DateTime.Now.AddHours(2), IsAllDay = false }, new Events { Id=2, Title="Testing 2", Start = DateTime.Now.AddHours(3), End = DateTime.Now.AddHours(4), IsAllDay = false } }; return Json(e.ToDataSourceResult(request), JsonRequestBehavior.AllowGet); } }

更多推荐

无法用数据填充Kendo Scheduler

本文发布于:2023-11-25 09:33:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629235.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   Kendo   Scheduler

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!