gpt4 book ai didi

javascript - Fullcalendar - 无法获取事件来显示 asp.net

转载 作者:行者123 更新时间:2023-12-03 02:33:39 24 4
gpt4 key购买 nike

我正在尝试实现 fullcalender,但无法显示示例数据。我一直在关注this guide .

我没有收到任何错误,但事件没有显示在日历中。我尝试了不同的解决方案,但我无法让它工作,而且我对 json 的经验非常有限,我希望得到一些帮助。

    public class CalendarController : BaseController
{

public ActionResult ShowCalendar()
{
return View();
}

public ActionResult GetMeetings(double start, double end)
{
using (var db = new ApplicationDbContext())
{
var fromDate = ConvertFromUnixTimestamp(start);
var toDate = ConvertFromUnixTimestamp(end);

var eventList = GetEvents();

var rows = eventList.ToArray();
return Json(rows, JsonRequestBehavior.AllowGet);
}
}

private static DateTime ConvertFromUnixTimestamp(double timestamp)
{
var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}
private List<Events> GetEvents()
{
List<Events> eventList = new List<Events>();

Events newEvent = new Events
{
id = "1",
title = "Event 1",
start = DateTime.Now.AddDays(1).ToString("s"),
end = DateTime.Now.AddDays(1).ToString("s"),
allDay = false
};

eventList.Add(newEvent);

newEvent = new Events
{
id = "1",
title = "Event 3",
start = DateTime.Now.AddDays(2).ToString("s"),
end = DateTime.Now.AddDays(3).ToString("s"),
allDay = false
};

eventList.Add(newEvent);

return eventList;
}

<head>

@section scripts{
<link rel='stylesheet' href='fullcalendar/fullcalendar.css' />
<script src='lib/jquery.min.js'></script>
<script src='lib/moment.min.js'></script>
<script src='fullcalendar/fullcalendar.js'></script>
<script type="text/javascript">

$(document).ready(function () {
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev, next, today',
center: 'title',
right: 'month, agendaWeek, agendaDay'
},
buttonText: {
prev: '<',
next: '>'
},
defaultView: 'month',
editable: false,
weekMode: 'liquid',
//allDaySlot: false,
selectTable: true,
//slotMinutes: 15,
events: function (start, end, timezone, callback) {
$.ajax({
url: "/calendar/getmeetings/",
type: 'GET',
dataType: 'json',
success: function (start, end, timezone, callback) {
alert('success');
},
error: function (start, end, timezone, callback) {
alert('there was an error while fetching events!');
},
data: {
// our hypothetical feed requires UNIX timestamps
start: start.unix(),
end: end.unix()
}

});
}
});
});

</script>
}
</head>
<br />
<div class="jumbotron">
<h1>Event Calendar</h1>
<div id="calendar"></div>
</div>

最佳答案

我注意到,您没有特别仔细地遵循本教程,并且正在使用不同的方法来获取事件。

其中,您只是忘记将事件列表传递回 fullCalendar。您需要执行 fullCalendar 提供给您的回调函数,并向其提供您的事件。

您对“成功”和“错误”回调参数的定义是无意义的,顺便说一句 - 您需要检查 jQuery $.ajax 文档( http://api.jquery.com/jquery.ajax/ )以查看提供的内容:

success: function (response) { //response will contain the JSON data from the server
callback(response); //pass the data to fullCalendar. You can pass "response" directly, assuming the response directly contains a JSON array of events
},
error: function(jqXHR) {
alert(jqXHR.responseText);
}

参见https://fullcalendar.io/docs/event_data/events_function/了解更多详情。

关于javascript - Fullcalendar - 无法获取事件来显示 asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48624384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com