FullCalendar events from asp.net ASHX page not displaying

前端 未结 7 1125
慢半拍i
慢半拍i 2021-01-14 15:36

I have been trying to add some events to the fullCalendar using a call to a ASHX page using the following code.

Page script:



        
相关标签:
7条回答
  • 2021-01-14 16:05

    I struggled with this issue and resolved it using an .ashx handler as follows

    My return class looks like…

     public class Event
        {
            public Guid id { get; set; }
            public string title { get; set; }
            public string description { get; set; }
            public long start { get; set; }
            public long end { get; set; }
            public bool allDay { get; set; }
        }
    

    Where DateTime values are converted to long values using…

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

    And the ProcessRequest looks like…

    public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            DateTime start = new DateTime(1970, 1, 1);
            DateTime end = new DateTime(1970, 1, 1);
            try
            {
                start = start.AddSeconds(double.Parse(context.Request.QueryString["start"]));
                end = end.AddSeconds(double.Parse(context.Request.QueryString["end"]));
            }
            catch
            {
                start = DateTime.Today;
                end = DateTime.Today.AddDays(1);
            }
            List<Event> evList = new List<Event>();
            using (CondoManagerLib.Linq.CondoDataContext Dc = new CondoManagerLib.Linq.CondoDataContext(AppCode.Common.CGlobals.DsnDB))
            {
                evList = (from P in Dc.DataDailySchedules
                          where P.DateBeg>=start && P.DateEnd<=end
                          select new Event
                          {   description = P.Description,
                              id = P.RecordGuid,
                              title = P.Reason,
                              start = ConvertToTimestamp(P.DateBeg),
                              end = ConvertToTimestamp(P.DateEnd),
                              allDay = IsAllDay(P.DateBeg, P.DateEnd)
                          }).ToList();
            }
            System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            String sJSON = oSerializer.Serialize(evList);
            context.Response.Write(sJSON);
        }
    

    And my Document Ready…

    >  $(document).ready(function () {
    >             $('#calendar').fullCalendar({
    >                 header: { left: 'title', center: 'prev,today,next', right: 'month,agendaWeek,agendaDay' },
    >                 editable: false,
    >                 aspectRatio: 2.1,
    >                 events: "CalendarEvents.ashx",
    >                 eventRender: function (event, element) {
    >                     element.qtip({
    >                         content: event.description,
    >                         position: { corner: { tooltip: 'topLeft', target: 'centerLeft'} },
    >                         style: { border: { width: 1, radius: 3, color: '#000'},
    >                             padding: 5,
    >                             textAlign: 'center',
    >                             tip: true, 
    >                             name: 'cream' 
    >                         }
    >                     });
    >                 }
    >             })
    >         });
    

    The qTip pluging can be found at http://craigsworks.com/projects/qtip/

    Hope this helps.

    0 讨论(0)
提交回复
热议问题