简体   繁体   English

FullCalendar从服务器获取事件不起作用

[英]FullCalendar fetching events from server not working

I am trying to fetch events from my LocalDB server and have them display on my calendar, but they aren't appearing. 我正在尝试从LocalDB服务器中获取事件,并将其显示在我的日历上,但没有出现。

I am using the following method to fetch the events. 我正在使用以下方法来获取事件。

public JsonResult GetEvents(double start, double end)
{
    var fromDate = ConvertFromUnixTimestamp(start);
    var toDate = ConvertFromUnixTimestamp(end);

    var eventList = from e in db.Events
                    select new
                    {
                        ID = e.ID,
                        Title = e.Title,
                        StartDate = e.StartDate.ToString("s"),
                        EndDate = e.EndDate.ToString("s"),
                        EventType = e.EventType,
                        Hours = e.Hours,
                        AllDay = true
                    };

    var rows = eventList.ToArray();

    return Json(rows, JsonRequestBehavior.AllowGet);
}

private static DateTime ConvertFromUnixTimestamp(double timestamp)
{
    var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
    return origin.AddSeconds(timestamp);
}

My calendar is rendered as follows: 我的日历显示如下:

@Styles.Render("~/Content/fullcalendar")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/fullcalendar")

<br />
<div id="calendar"></div>
<br />

<script type="text/javascript">
$(document).ready(function () {
    $('#calendar').fullCalendar({
        header: {
            left: 'title',
            center: '',
            right: 'prev,next today' },
        defaultView: 'month',
        weekends: false,
        editable: false,
        events: "/Home/GetEvents/"    });
});
</script>

Any help is greatly appreciated. 任何帮助是极大的赞赏。

EDIT: 编辑:

This is in my web console: 这是在我的Web控制台中:

no element found abort:1:1
Use of getPreventDefault() is deprecated.  Use defaultPrevented instead. browserLink:37:40278
no element found send:1:1
no element found send:1:1
no element found send:1:1
no element found
GET http://localhost:54802/Home/GetEvents/ [HTTP/1.1 500 Internal Server Error 10ms]

Your response is not conform to fullCalendar expected output. 您的回应不符合fullCalendar的预期输出。 If you see the doc, you understand that each events needs to have at least these parameters: 如果您看到此文档,则将了解每个事件至少需要具有以下参数:

  • title 标题
  • start 开始

In your case the code should be like this: 在您的情况下,代码应如下所示:

public JsonResult GetEvents(double start, double end)
{
    var fromDate = ConvertFromUnixTimestamp(start);
    var toDate = ConvertFromUnixTimestamp(end);

    var eventList = from e in db.Events
                    select new
                    {
                        id = e.ID,
                        title = e.Title,
                        start = e.StartDate.ToString("s"),
                        end = e.EndDate.ToString("s"),
                        eventType = e.EventType,
                        hours = e.Hours,
                        allDay = true
                    };

    var rows = eventList.ToArray();

    return Json(rows, JsonRequestBehavior.AllowGet);
}

The first problem is, as I think, the name of variables for each event. 我认为,第一个问题是每个事件的变量名称。 This not match what fullCalendar is expecting. 这与fullCalendar的预期不符。

With this new one GetEvents method fullCalendar should understand and print your output. 使用这一新的GetEvents方法,fullCalendar应该可以理解并打印输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM