views:

2346

answers:

2

I am using asp.net mvc to list the events in the jquery full calendar. Below is the script i am using to list the events through json from 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);
  }
 });

But the above script not showing any events in the calendar. What am i doing wrong in the above script?

+1  A: 

It has been solved when i parsed the date from the events from json as:

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);

                    });

        },
Prasad
hello again prasad, glad you got this to work. would you be able to tag this question as well (tag: "fullcalendar"). thank you so much!
arshaw
Hi prasad, I am also facing the same problem, as you already have been sort this, pls tell me what is the dateFormat() method and what the 10 will do in replace method.please suggest me how to create my JSON response object so that the data can be displayed in fullcalendarThanks
Bhupi
A: 

you can also fromat the Date string on the server side with

DateTime.Now.ToString("s"):

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

Thomas