Javascript FullCalendar.js未在ASP.NET MVC应用程序中显示事件
我正在尝试在ASP.NET MVC应用程序中使用fullcalendar.com来显示事件。我已经加载了一些测试数据,但是它没有显示在日历中(日历显示)。我已经用JavaScript实现了一些错误处理,控制器的调用似乎工作正常 另外,当直接转到控制器URL时,正确的数据也在那里 助手类Javascript FullCalendar.js未在ASP.NET MVC应用程序中显示事件,javascript,json,asp.net-mvc,jquery-ui,fullcalendar,Javascript,Json,Asp.net Mvc,Jquery Ui,Fullcalendar,我正在尝试在ASP.NET MVC应用程序中使用fullcalendar.com来显示事件。我已经加载了一些测试数据,但是它没有显示在日历中(日历显示)。我已经用JavaScript实现了一些错误处理,控制器的调用似乎工作正常 另外,当直接转到控制器URL时,正确的数据也在那里 助手类 public class FCEvents { public int ID; public string EventTitle; public string StartDa
public class FCEvents
{
public int ID;
public string EventTitle;
public string StartDateString;
public string EndDateString;
public static List<FCEvents> LoadAllAppointmentsInDateRange()
{
using (EventDb ev = new EventDb())
{
var rslt =
from e in ev.Events
select new EventsListViewModel
{
EventID = e.EventID,
EventTitle = e.EventTitle,
CourseCode = e.Course.CourseCode,
StartDate = e.StartDate,
FinishDate = e.FinishDate,
Location = e.Location
};
List<FCEvents> result = new List<FCEvents>();
foreach (var item in rslt)
{
FCEvents rec = new FCEvents ();
rec.ID = item.EventID;
rec.EventTitle = item.EventTitle + "-" + item.CourseCode + "-" + item.Location;
rec.StartDateString = item.StartDate.ToString("s");
rec.EndDateString = item.FinishDate.ToString("s");
result.Add(rec);
}
return result;
}
}
}
JavaScript
@section Scripts {
<script type="text/javascript">
$(document).ready(function () {
GetEvents();
});
function GetEvents() {
$('#calendar').fullCalendar({
header: {
left: '',
center: 'title',
right: 'prev, next, today'
},
defaultView: 'month',
editable: false,
selectable: true,
dataType: 'json',
eventSources: [
{
url: '@Url.Action("GetEvents")',
type: 'POST',
backgroundColor: 'red',
success: function () {
alert('we got the events!');
},
error: function () {
alert('there was an error while fetching events!');
},
}],
});
}
</script>
@节脚本{
$(文档).ready(函数(){
GetEvents();
});
函数GetEvents(){
$(“#日历”).fullCalendar({
标题:{
左:'',
中心:'标题',
右图:“上一页,下一页,今天”
},
defaultView:'月份',
可编辑:false,
是的,
数据类型:“json”,
事件来源:[
{
url:“@url.Action(“GetEvents”)”,
键入:“POST”,
背景颜色:“红色”,
成功:函数(){
警惕(“我们得到了事件!”);
},
错误:函数(){
警报('获取事件时出错!');
},
}],
});
}
}
这是来自控制器的结果:
“[{”ID:1,“事件标题”:“急救T-\r\nHLTAID001南摩朗”,“开始日期字符串”:“2015-08-14T10:00:00”,“结束日期字符串”:“2015-08-15T00:00:00”},{”ID:3,“事件标题”:“急救F-\r\nHLTAID001里士满”,“开始日期字符串”:“2015-08-11T02:08:00”,“结束日期字符串”:“2015-08-13T00:00:00”},{”ID:4,“事件标题”:“消防T-\r\nHLTAID001里士满”StartDateString:“2015-08-20T03:08:00”,“EndDateString:“2015-08-25T00:00:00”},{“ID”:2000,“EventTitle:“Testing-\r\nHLTAID001 Mill Park”,“StartDateString:“2015-08-15T00:00:00”,“EndDateString:“2015-08-20T00:00:00”}”
任何帮助都将不胜感激,我已经花了两天的时间来讨论这个问题,我似乎无法理解
简单回顾一下,日历可以工作,但没有显示任何事件 我一直在处理同样的问题,所以我想我知道这种挫折感。然而,我尝试了下面的示例,这对我来说是有效的。我看不出有什么不同,只有@Url.Action在JavaScript中给了我一个错误
eventSources: [
{
url: '/Agenda/GetEvents/',
type: 'POST',
data: { userId: $('#UserId').val() },
backgroundColor: 'red',
success: function () {
alert('we got the events!');
},
error: function () {
alert('there was an error while fetching events!');
},
}
],
加载页面时(即调用
GetEvents()
时),是否实际调用了操作/控制器?eventSources
是否实际工作?似乎是这样,当我将@Url.Action更改为其他控制器时,我会收到错误消息。由于存在相同的问题,甚至没有调用GetEvents()。我在方法的第一行设置了一个断点,但它没有达到断点。嗨,Jelle,我插入了你的修改,我只是用eventId交换了userId,事件仍然不会显示在日历中,尽管我仍在检索“we got the events”(我们得到了事件),你还有其他建议吗?你们有什么进展吗?我尝试自己使用FullCalendar,但它没有调用我的GetEvents方法
eventSources: [
{
url: '/Agenda/GetEvents/',
type: 'POST',
data: { userId: $('#UserId').val() },
backgroundColor: 'red',
success: function () {
alert('we got the events!');
},
error: function () {
alert('there was an error while fetching events!');
},
}
],