0

我正在尝试FullCalendar在我的 MVC 应用程序中呈现 (1.5.3),如下所示:

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay'
    },
    titleFormat: { day: '' },
    defaultView: 'month',
    events: "/Schedule/GetCal"
});

生成的JSON字符串/Schedule/GetCal如下所示:

{id:"5BFAA9C3-9437-49B0-A657-5DA47CDEA409",projectId:"5BFAA9C3-9437-49B0-A657-5DA47CDEA409",title:"Orem City Parking Lot",start:"2012-07-11",end:"",allDay:"true",type:"goal",textColor:"white",backgroundColor:"green",borderColor:"black",crew:""},
{id:"33910A42-C5F0-42FA-AB36-C315BDDAF964",projectId:"33910A42-C5F0-42FA-AB36-C315BDDAF964",title:"Thanksgiving Point - Buster",start:"2012-07-28",end:"",allDay:"true",type:"goal",textColor:"white",backgroundColor:"green",borderColor:"black",crew:""}

它不会在页面上呈现任何事件。但是,当我这样称呼它时:

$('#calendar').fullCalendar({
    header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,basicWeek,basicDay'
    },
    titleFormat: { day: '' },
    defaultView: 'month',
    events: [{id:"5BFAA9C3-9437-49B0-A657-5DA47CDEA409",projectId:"5BFAA9C3-9437-49B0-A657-5DA47CDEA409",title:"Orem City Parking Lot",start:"2012-07-11",end:"",allDay:"true",type:"goal",textColor:"white",backgroundColor:"green",borderColor:"black",crew:""},
            {id:"33910A42-C5F0-42FA-AB36-C315BDDAF964",projectId:"33910A42-C5F0-42FA-AB36-C315BDDAF964",title:"Thanksgiving Point - Buster",start:"2012-07-28",end:"",allDay:"true",type:"goal",textColor:"white",backgroundColor:"green",borderColor:"black",crew:""}
   ]
});

它按预期工作。我需要更改JSON字符串的格式吗?或者,我怎么称呼它?

4

2 回答 2

0

您的/Schedule/GetCal脚本需要返回一个事件数组 - 由 JSON 字符串中事件集周围的方括号表示。

目前,您似乎只是返回了一个逗号分隔的事件列表,而这些事件并没有按照您的期望进行解释。

您的输出需要如下所示:

["0",{"allDay":"","title":"去上班","id":"821","end":"2011-06-06 14:00:00","start ":"2011-06-06 06:00:00"},"1",{"allDay":"","title":"Party at Toms","id":"822","end": "2011-06-10 21:00:00","开始":"2011-06-10 16:00:00"}]

于 2012-07-28T11:31:29.907 回答
0

这篇文章帮助我弄清楚:ASP.Net MVC、jQuery 和 FullCalendar

显然在FullCalendar1.5.3 中,asp.net mvc您需要返回一个List<>已转换.ToArray()的,然后在JSON. 一旦我这样做了,结果就如我预期的那样出现在日历中。

我曾经alert(data)在浏览器中看到结果,而不是我在上面发布的字符串

{Object},{Object}
于 2012-07-28T18:49:07.117 回答