Pergunta

Estou usando o ASP.NET MVC para listar os eventos no calendário completo do jQuery. Abaixo está o script que estou usando para listar os eventos através do JSON da MVC.

$('#calendar').fullCalendar({
        theme: true,
        editable: true,
        disableDragging: true,
        disableResizing: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
        },
        events: function(start, end, callback) {
        // do some asynchronous ajax
        $.getJSON("/User/GetEvents/",
            {
                    start: dateFormat(start.getTime()),
                    end: dateFormat(end.getTime())
            },
            function(result) {
                    // then, pass the CalEvent array to the callback
                    callback(result);
            })
        },
        eventClick : function(event) {
            editEventShow(event);
        },
        dayClick : function(dayDate){
            addEventShow(dayDate, this);
        }
    });

Mas o script acima não mostra nenhum evento no calendário. O que estou fazendo de errado no script acima?

Foi útil?

Solução

Foi resolvido quando eu analisei a data dos eventos do JSON como:

events: function(start, end, callback) {
            // do some asynchronous ajax
            contentType:"application/json; charset=utf-8",
            $.getJSON("/User/GetEvents/",
                    {
                            start: dateFormat(start.getTime()),
                            end: dateFormat(end.getTime())
                    },
                    function(result) {
                            if(result != null)
                            {
                                for (i in result) {
                                    var calEvent = result[i];
                                    calEvent.date = new Date(parseInt(calEvent.date.replace("/Date(", "").replace(")/", ""), 10));
                                    calEvent.start = new Date(parseInt(calEvent.start.replace("/Date(", "").replace(")/", ""), 10));
                                    calEvent.end = new Date(parseInt(calEvent.end.replace("/Date(", "").replace(")/", ""), 10));
                                }
                            }

                            var calevents = result;
                            // then, pass the CalEvent array to the callback
                            callback(calevents);

                    });

        },

Outras dicas

Você também pode formatar a string de data do lado do servidor com

DateTime.Now.ToString("s"):

Ver: http://weblogs.asp.net/gunnarpeipman/archive/2010/02/03/using-fullcalendar-jquery-component-with-asp-net-mvc.aspx

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top