简体   繁体   English

未触发eventRender Fullcalendar ASP.net C#Webforms

[英]eventRender not being triggered Fullcalendar ASP.net C# webforms

I'm having an issue with displaying events on fullcalendar. 我在全日历上显示事件时遇到问题。 I am using ASP.net webforms with C#. 我在C#中使用ASP.net Webforms。 I have ashx handler which I am calling to load the values from the database and this is then being formatted into a json response that is being sent back. 我有ashx处理程序,我正在调用该处理程序从数据库中加载值,然后将其格式化为json响应并发送回。 Below is the javascript being used to generate the calendar: 以下是用于生成日历的javascript:

$(document).ready(function () {

// update Dialog


// page is now ready, initialize the calendar...

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

var calendar = $('#calendar').fullCalendar({
    // put your options and callbacks here
    header:
    {
        left: 'title',
        center: '',
        right: 'month,agendaDay,agendaWeek, prev,next'
    },
    height: 600,
    //contentHeight: auto,
    titleFormat: 'MMMM D YYYY',
    columnFormat: 'ddd D/M',
    defaultView: 'agendaWeek',
    handleWindowResize: true,
    allDaySlot: true,
    minTime: '09:00:00',
    maxTime: '18:00:00',
    slotLabelFormat: 'h(:mm)a',
    slotLabelInterval: '01:00:00',
    firstDay: 1,
    weekends: false,
    hiddenDays: [6, 7],
    selectHelper: true,
    select: selectDate,
    editable: true,
    eventDrop: eventDropped,
    eventResize: eventResized,
    events: {
        url: 'JsonResponse.ashx',
        color: 'yellow',
        error: function () {
            alert('Error while Getting events!');
        }
    },

    eventRender: function (event, element) {
        console.log("here");
        //alert(event.title);
        element.qtip({
            content: event.description,
            style: {
                border: {
                    width: 1,
                    radius: 3,
                    color: '#2779AA'

                },
                padding: 10,
                textAlign: 'center',
                tip: true, // Give it a speech bubble tip with automatic corner detection
                name: 'cream' // Style it according to the preset 'cream' style
            },
            error: function () {
                alert('Error while Getting events!');
            },
            success: function () {
                alert('Success!');
            }

        });
    }


});

});

This is the JSON response I am getting in the browser network trace: 这是我在浏览器网络跟踪中得到的JSON响应:

"{"id":8,"title":"tester","start":"2018-01-30","end":"2018-01-30","allday":"false","description":"tester"}" “{” ID “:8中,” 标题 “:” 测试仪 “ ”启动“: ”2018年1月30日“, ”端“: ”2018年1月30日“, ”阿迪“: ”假“,” 描述“:” 测试 “}”

ASHX file used to generate the JSON: 用于生成JSON的ASHX文件:

{


public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "application/json";

    DateTime start = new DateTime(1970, 1, 1);
    DateTime end = new DateTime(1970, 1, 1);

    start = Convert.ToDateTime(context.Request.QueryString["start"]);
    end = Convert.ToDateTime(context.Request.QueryString["end"]);


    String result = String.Empty;

    result += "\"[";
    eventSerializer newEvent = new eventSerializer();
    List<int> idList = new List<int>();
    foreach (CalendarEvent cevent in EventDAO.getEvents(start, end))
    {

        String allDay = "true";
        if (ConvertToTimestamp(cevent.start).ToString().Equals(ConvertToTimestamp(cevent.end).ToString()))
        {

            if (cevent.start.Hour == 0 && cevent.start.Minute == 0 && cevent.start.Second == 0)
            {
                allDay = "true";
            }
            else
            {
                allDay = "false";
            }
        }
        else
        {
            if (cevent.start.Hour == 0 && cevent.start.Minute == 0 && cevent.start.Second == 0
                && cevent.end.Hour == 0 && cevent.end.Minute == 0 && cevent.end.Second == 0)
            {
                allDay = "true";
            }
            else
            {
                allDay = "false";
            }
        }

        newEvent.id = cevent.id;
        newEvent.title = cevent.title;
        newEvent.start = cevent.start.ToString("yyyy-MM-dd");;
        newEvent.end = cevent.end.ToString("yyyy-MM-dd");;
        newEvent.allday = allDay;
        newEvent.description = cevent.description;

    }

    JavaScriptSerializer js = new JavaScriptSerializer();
    string jsonData = js.Serialize(newEvent);
    context.Response.Write(jsonData);
}

public bool IsReusable
{
    get
    {
        return false;
    }
}

private long ConvertToTimestamp(DateTime value)
{


    long epoch = (value.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
    return epoch;

}

}

public class eventSerializer
{

public int id;
public string title;
public string start;
public string end;
public string allday;
public string description;
}

I have attempted to add a console.log into the eventRender function and it doesn't seem to be getting triggered. 我试图将console.log添加到eventRender函数中,但似乎没有被触发。 The events are not being added to the calendar either. 这些事件也不会添加到日历中。 I am not getting any errors. 我没有任何错误。

Any suggestions on where I am going wrong would be greatly appreciated! 关于我要去哪里的任何建议将不胜感激!

Thanks to @ADyson it appears that the issue was to do with the JSON not being returned in the correct format. 感谢@ADyson,看来问题出在JSON格式不正确。 After adding the JSON into a list and serializing the list the events are showing on the calendar. 将JSON添加到列表中并序列化列表后,事件将显示在日历上。 See below for the updated ASHX. 有关更新的ASHX,请参见下文。

public class JsonResponse : IHttpHandler, IRequiresSessionState
{

public void ProcessRequest(HttpContext context)
{
    context.Response.ContentType = "application/json";

    DateTime start = new DateTime(1970, 1, 1);
    DateTime end = new DateTime(1970, 1, 1);

    start = Convert.ToDateTime(context.Request.QueryString["start"]);
    end = Convert.ToDateTime(context.Request.QueryString["end"]);

    List<int> idList = new List<int>();
    List<object> eventList = new List<object>();

    foreach (CalendarEvent cevent in EventDAO.getEvents(start, end))
    {
        eventSerializer newEvent = new eventSerializer();

        bool allDay = true;
        if (ConvertToTimestamp(cevent.start).ToString().Equals(ConvertToTimestamp(cevent.end).ToString()))
        {

            if (cevent.start.Hour == 0 && cevent.start.Minute == 0 && cevent.start.Second == 0)
            {
                allDay = true;
            }
            else
            {
                allDay = false;
            }
        }
        else
        {
            if (cevent.start.Hour == 0 && cevent.start.Minute == 0 && cevent.start.Second == 0
                && cevent.end.Hour == 0 && cevent.end.Minute == 0 && cevent.end.Second == 0)
            {
                allDay = true;
            }
            else
            {
                allDay = false;
            }
        }

        idList.Add(cevent.id);

        newEvent.id = cevent.id;
        newEvent.title = cevent.title;
        newEvent.start = cevent.start.ToString("yyyy-MM-dd HH:mm");
        newEvent.end = cevent.end.ToString("yyyy-MM-dd HH:mm");
        newEvent.allDay = allDay;
        newEvent.description = cevent.description;

        eventList.Add(newEvent);
    }

    //store list of event ids in Session, so that it can be accessed in web methods
    context.Session["idList"] = idList;

    JavaScriptSerializer js = new JavaScriptSerializer();
    string jsonData = js.Serialize(eventList);
    context.Response.Write(jsonData);
}

public bool IsReusable
{
    get
    {
        return false;
    }
}

private long ConvertToTimestamp(DateTime value)
{
    long epoch = (value.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
    return epoch;
}

}

public class eventSerializer
{
public int id;
public string title;
public string start;
public string end;
public bool allDay;
public string description;
}

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

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