eventRender不会在fullcalendar上呈现或显示事件

时间:2017-02-06 08:00:30

标签: javascript jquery asp.net-mvc asp.net-mvc-5 fullcalendar

美好的一天,我使用fullcalendar插件在我的日历上显示事件。现在我在我的日历中显示事件时遇到了问题。我正在使用json结果来获取将在我的日历上显示的数据..

这是我的代码

控制器:

[DontWrapResult]
public JsonResult GetCalendarEvents(string start, string end)
{
    var fromDate = Convert.ToDateTime(start);
    var toDate = Convert.ToDateTime(end);

    var result = _utils.GetEventsCalendar("ALL", fromDate, toDate);
    var eventList = from item in result
        select new
        {
            id = item.CalendarId.ToString(),
            title = item.Title,
            description = item.Description,
            start = item.FromDate.ToLocalTime().ToString("s"),
            end = item.EndDate.HasValue ? item.EndDate.Value.ToLocalTime().ToString("s") : item.FromDate.ToLocalTime().ToString("s"),
            NoofGuests = item.NoofGuests,
            allDay = item.AllDay,
            type = item.CalType,
            requestedBy = item.RequestedBy,
            driverName = item.DriverName,
            providerName = item.ProviderName,
            phoneNo = item.PhoneNo,
            controlNumber = item.ControlNumber,
            status =item.StatusId
        };
    var rows = eventList.ToArray();
    return Json(rows, JsonRequestBehavior.AllowGet);
}

然后在我的javascript中:

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

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
    },
    droppable: false, // this allows things to be dropped onto the calendar
    events: '@Url.Action("GetCalendarEvents/")',
    eventRender: function (event, element) {
        element.attr('href', 'javascript:void(0);');
        if (event.start <date && event.end <date) {
            element.css('background-color', '#ed5565');
            element.css('border', '1px solid #ed5565');
        } else if (event.start <=date && event.end >= date) {
            element.css('background-color', '#f8ac59');
            element.css('border', '1px solid #f8ac59');
        }
        if (event.status == 1) {
            element.css('background-color', '#0000FF');
            element.css('border', '1px solid #0000FF');
        } else if (event.status == 4)
        {
            element.css('background-color', '#00CC33');
            element.css('border', '1px solid #00CC33');
        }
        element.click(function () {
            if (event.type == 'Event') {
                $('#forBook').hide();
                $('#permitdetails').hide();
                $('#delPer').show();
                var url = '@Url.Action("Edit", "Events")?id=' + event.id;
            }
            else if (event.type == 'ApproveBook') {
                $('#forBook').show();
                $('#permitdetails').hide();
                $('#delPer').show();
                $("#NoofGuests").html(event.NoofGuests);
            }
            else {
                $('#forBook').hide();
                $('#permitdetails').hide();
                $('#delPer').show();
                var url = '@Url.Action("Edit", "Announcements")?id=' + event.id;
            }

            if (event.type == 'DeliveryPermit') {
                $('#delPer').hide();
                $('#permitdetails').show();
                $("#controlNo").html(event.controlNumber);
                $("#requestby").html(event.requestedBy);
                $("#deliverydate").html(moment(event.start).format('MMM Do'));
                $("#contractor").html(event.providerName);
                $("#contact").html(event.phoneNo);
                $("#drivername").html(event.driverName);
                if (event.status == 1) { $("#status").html("Arrived"); }
                else if (event.status == 4) { $("#status").html("Completed"); }
                else { $("#status").html("Submitted"); }

                //getDetails(event.id);

                var urls = '@Url.Action("Calendarpermit", "AdminHome")?id=' + event.id + '&strHide=' + "strHide";
                var url = '@Url.Action("Edit", "DeliveryPermits",new { area = "Permit" })/' + event.id
                $.ajax({
                    url: urls,
                    cache: false,
                    data: {id : event.id},
                    contentType: 'application/html; charset=utf-8',
                    type: "POST",
                    dataType: "html",
                    success: function (data){
                        $('#permitItem').html(data);
                    }
                });
            }

            if (event.type == 'Announcement') {
                $('#forBook').hide();
                $('#permitdetails').hide();
                $('#delPer').show();
                $("#startTime").html(moment(event.start).format('MMM Do '));
                $("#endTime").html(moment(event.start).format('MMM Do'));
            } else {
                $("#startTime").html(moment(event.start).format('MMM Do h:mm A'));
                $("#endTime").html(moment(event.end).format('MMM Do h:mm A'));
            }
            $("#eventInfo").html(event.description);

            $("#eventLink").attr('href', url);
            $("#eventContent").dialog({
                modal: true, title: event.title, width: 350
            });
        });
    }
});

我试图在eventRender中发出警报,但它没有在我的日历中传递或显示数据..我做错了什么?提前谢谢

0 个答案:

没有答案