fullcalendar停止显示来自控制器MVC 4事件 [英] fullcalendar stop showing events from controller mvc 4
问题描述
我在fullcalendar简单的事件说明一个问题。当我使用这个code第一次,这种日历显示我从我的数据库事件,两天后我一定要改变的东西,现在是完全地打破。感谢您的帮助!
这是我的Calendar.js
$(文件)。就绪(函数(){ GetEvents();});
功能GetEvents()
{ $('#日历')。fullCalendar({
主题:假的,
标题:{
左:'preV,今天下一个',
中心:'标题',
对: ''
},
默认视图:'月', 编辑:假的, 数据类型:JSON 事件:{
网址:'/日历/ MountLoad',
输入:POST,
数据:{
},
错误:函数(){
警报('而获取的事件有一个错误!);
}, 成功:函数(){ }
} });};
这是我的日历控制器
公共类CalendarController:控制器
{
私人MountManager mountManager;
私人EmployeeController employeeManager; 公共CalendarController()
{
this.mountManager =新MountManager();
this.employeeManager =新EmployeeController();
}
公共JsonResult MountLoad()
{
VAR的事件= mountManager.MountList();
VAR EVENTLIST =从E在事件
新选择
{
ID = e.Id,
地方= e.Place,
说明= e.Description,
名称= e.Name,
DateFrom = e.DateFrom.ToString(S),
DateTo = e.DateTo.ToString(S) }; 返回JSON(EVENTLIST,JsonRequestBehavior.AllowGet);
} 公众的ActionResult指数()
{
返回查看();
}}
我会建议你改变你的 AJAX
,并使用 .MAP
将数据与 fullcalendar
映射如下:
函数GetEvents()
{
$阿贾克斯({
数据类型:JSON
的contentType:应用/ JSON
数据:{},
网址:/日历/ MountLoad
数据类型:JSON
成功:功能(数据){
$('#日历')。fullCalendar({
主题:假的,
标题:{
左:'preV,今天下一个',
中心:'标题',
对: ''
},
默认视图:'月',
编辑:假的,
郎咸平:EN-IN,
eventLimit:1,
eventLimitText:更多,
weekMode:液体,
事件:$ .MAP(数据,功能(项目一){//这是你需要照顾
VAR事件=新的对象();
event.start =时刻(item.DateFrom).utc();
event.end =时刻(item.DateTo).utc();
event.title = item.name;
event.brief = item.description;
event.place = item.place;
event.id = item.id;
返回事件;
}), }); },
错误:功能(XMLHtt prequest,textStatus,errorThrown){
$(#cal_error)文本(errorThrown)。 //处理错误
}
});
}
注意:您需要添加moment.js并参考它的未来充满日历支持
请参阅 <一个href=\"http://stackoverflow.com/questions/28556711/why-globalization-in-web-config-makes-fullcalendar-not-to-render-events\">this问题 如果您有任何疑问
I have a problem with simple event show in fullcalendar. First time when I use this code, this calendar shows me my events from database, after two days I must change something and now it's completly broken. Thanks for your help!
This is my Calendar.js
$(document).ready(function () {
GetEvents();
});
function GetEvents()
{
$('#calendar').fullCalendar({
theme: false,
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
defaultView: 'month',
editable: false,
dataType: "json",
events: {
url: '/Calendar/MountLoad',
type: 'POST',
data: {
},
error: function () {
alert('there was an error while fetching events!');
},
success: function () {
}
}
});
};
And this is my calendar controller
public class CalendarController : Controller
{
private MountManager mountManager;
private EmployeeController employeeManager;
public CalendarController()
{
this.mountManager = new MountManager();
this.employeeManager = new EmployeeController();
}
public JsonResult MountLoad()
{
var events = mountManager.MountList();
var eventList = from e in events
select new
{
id = e.Id,
place = e.Place,
description = e.Description,
name = e.Name,
DateFrom = e.DateFrom.ToString("s"),
DateTo = e.DateTo.ToString("s")
};
return Json(eventList, JsonRequestBehavior.AllowGet);
}
public ActionResult Index()
{
return View();
}
}
I would suggest you to change your ajax
and use .map
to map your data with fullcalendar
as below:
function GetEvents()
{
$.ajax({
dataType: "json",
contentType: "application/json",
data: "{}",
url: "/Calendar/MountLoad",
dataType: "json",
success: function (data) {
$('#calendar').fullCalendar({
theme: false,
header: {
left: 'prev,next today',
center: 'title',
right: ''
},
defaultView: 'month',
editable: false,
lang: 'en-IN',
eventLimit: 1,
eventLimitText: 'More',
weekMode: 'liquid',
events: $.map(data, function (item, i) {//This is where you need to take care
var event = new Object();
event.start = moment(item.DateFrom).utc();
event.end = moment(item.DateTo).utc();
event.title = item.name;
event.brief = item.description;
event.place = item.place;
event.id=item.id;
return event;
}),
});
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$("#cal_error").text(errorThrown); //Handle Error
}
});
}
Note : You need to add moment.js and refer it for future full calendar support
Refer this question if you have any doubts
这篇关于fullcalendar停止显示来自控制器MVC 4事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!