c# - 问题获取事件完整日历 asp.net / c#
问题描述
首先,我会说我在这里尝试了很多样本,但其他样本没有成功,所以在这里发布建议。
我正在使用完整日历。
这是开始:
$('#calendar')
.fullCalendar({
allDaySlot: false,
customButtons: {
reload: {
text: '+1 Year',
click: function() {
$('#calendar').fullCalendar('gotoDate', new Date(new Date().setFullYear(new Date().getFullYear() + 1)));
}
}
},
themeSystem: 'bootstrap4',
defaultView: 'agendaWeek',
eventClick: updateEvent,
selectable: true,
selectHelper: true,
events: "JsonResponse.ashx",
and other attributes.....
问题是日历没有显示事件。
JsonResonse.ashx 返回如下字符串:
[{id: '1029',title: 'mr 1',clientphone: '1234556654',clientemail: 'mr1@gmail.com',start: '2018-05-21 10:00',end: '2018-05-21 11:45',allDay:false,description: 'New test on a new calender'},{id: '1030',title: 'mr 2',clientphone: '123456',clientemail: 'mr2@gmail.com',start: '2018-05-25 09:00',end: '2018-05-25 11:45',allDay:false,description: 'i like pringles'}]
但是在 Firefox 上,我看到它不会使事件出现一些错误:
SyntaxError: JSON.parse: expected property name or '}' at line 1 column 3 of the JSON data
所以我使用和替换事件:“JsonResponse.ashx”,返回字符串
[{id: '1029',title: 'mr 1',clientphone: '1234556654',clientemail: 'mr1@gmail.com',start: '2018-05-21 10:00',end: '2018-05-21 11:45',allDay:false,description: 'New test on a new calender'},{id: '1030',title: 'mr 2',clientphone: '123456',clientemail: 'mr2@gmail.com',start: '2018-05-25 09:00',end: '2018-05-25 11:45',allDay:false,description: 'i like pringles'}]
使 JSON 返回的代码:
return "{" +
"id: '" + cevent.id + "'," +
"title: '" + HttpContext.Current.Server.HtmlEncode(cevent.title) + "'," +
"clientphone: '" + HttpContext.Current.Server.HtmlEncode(cevent.clientphone) + "'," +
"clientemail: '" + HttpContext.Current.Server.HtmlEncode(cevent.clientemail) + "'," +
"start: '" + (cevent.start).ToString("yyyy-MM-dd HH:mm") + "'," +
"end: '" + (cevent.end).ToString("yyyy-MM-dd HH:mm") + "'," +
"allDay:" + allDay + "," +
"description: '" + HttpContext.Current.Server.HtmlEncode(cevent.description) + "'" +
"},";
基本上我结合所有事件然后返回。
就像那样,它工作正常并将事件放在日历上。我在这里做错了什么?
谢谢
解决方案
JsonResponse.ashx 处理程序返回的 json 无效。你是如何生成json的?我建议使用NewtonSoft使用JsonConvert.SerializeObject方法将您的事件列表序列化为 json
这是您的 ashx 处理程序应返回的有效 json。请注意属性名称和值周围的双引号。
[{
"id": "1029",
"title": "mr1",
"clientphone": "1234556654",
"clientemail": "mr1@gmail.com",
"start": "2018-05-2110: 00",
"end": "2018-05-2111: 45",
"allDay": false,
"description": "Newtestonanewcalender"
},
{
"id": "1030",
"title": "mr2",
"clientphone": "123456",
"clientemail": "mr2@gmail.com",
"start": "2018-05-2509: 00",
"end": "2018-05-2511: 45",
"allDay": false,
"description": "ilikepringles"
}]
推荐阅读
- c++ - 第一次尝试使用new动态创建struct数组,程序挂起无误
- django - Django 如何热重载 Uwsgi 每个工人的 Singleton 值?
- java - 我正在使用 android 中的操作调用
- python - Pytest `pytest.raises(ValueError)` 似乎没有检测到`ValueError`
- android - 如何在设计支持库的 FragmentTabHost 中设置选项卡之间的分隔符?
- python - 如果元素以另一个列表中的元素结尾,则从列表中删除元素的结尾
- xml - 使用会话变量中的会话值将映射设置为 mule 3 中的有效负载
- python - 根据条件更改数据框的值
- python - 如何在python中使用1 0创建圆形
- ruby-on-rails - 在 Rails 5 中的 form_with 中保留页面重新加载时的复选框值