开发者

Jquery fullcalendar not showing events

I was very excited to see a calendar plugin like fullcalendar. I am trying to use fullcalendar to display events for each month. But the events are not displayed on the calendar.

My code is :

[AcceptVerbs(HttpVerbs.Get)]
public JsonResult HighlightCalendar()
{
    var tasksList = new List<HighlightMonthlyEvents>();

    tasksList.Add(new HighlightMonthlyEvents
    {
        id = 1,
        EventName = "Google search",
        EventStartDate = ToUnixTimespan(DateTime.Now),
        EventEndDate = ToUnixTimespan(DateTime.Now.AddHours(4)),
        url = "www.google.com"
    });
    tasksList.Add(new HighlightMonthlyEvents
    {
        id = 1,
        EventName = "Bing search",
        EventStartDate = ToUnixTimespan(DateTime.Now.AddDays(1)),
        EventEndDate = ToUnixTimespan(DateTime.Now.AddDays(1).AddHours(4)),
        url = "www.bing.com"
    });

    var highlightDays = Jayrock.Json.Conversion.JsonConvert.ExportToString(tasksList.ToArray());

    return Json(highlightDays, JsonRequestBehavior.AllowGet);
}


 <script type="text/javascript">
 $(function () {

// FullCalendar

$('.fullcalendar').fullCalendar({
theme: true,
header: {
 left: 'today prev,next',
 center: '',
开发者_如何学编程 right: ''
},
defaultView: 'month',
editable: false,
events: function (callback) {
 // do some asynchronous ajax
 contentType: "application/json; charset=utf-8",
        $.getJSON("/Test/HighlightCalendar/", null,
               function (result) {
                var calevents = new Array();
                var results = eval(result);
                eval(results.length);
                if (results != null) {
                 for (i in results) {
                  var calEvent = results[i];

                  calevents.push(calEvent)

                 }
                }
                alert(calevents.length);

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

               });
}

});

And as for my JSON, it looks like:

[{"id":1,"allDay":false,"title":"Google search","start":1279750267,"end":1279764667,"url":"www.google.com"},{"id":2,"allDay":false,"title":"Bing search","start":1279836667,"end":1279851067,"url":"www.bing.com"}]

What do you think about what is wrong?


This might probably has to do with quotes around your property and values.

Try to include quotes in both property and value and check your result.

I achieved the same without using JSON.js like this.

System.Web.Script.Serialization.JavaScriptSerializer eventListSerializer =
                                                                                    new System.Web.Script.Serialization.JavaScriptSerializer();
                string eventListJSON = eventListSerializer.Serialize(addevList);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜