Title: Jquery full calendar - get only current view events
Tags: jquery;ajax;asp.net-mvc;fullcalendar
Question: I read more on the subject but nothing clear so maybe anyone can help.
I am using JQuery FullCalendar with asp.net mvc and ajax to get a large number of events.
I want to limit that by only displaying event for current view and when the user clicks next/prev they load the events for that view and so on.
$("#calendar").fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
height: 'auto',  //altfel se prelungea mult in jos
defaultView: 'agendaWeek',
events: "/calendar/GetAllCalendarEvents/"  //gets the events.
I saw a start/end date, but how do you use it? I want to only fetch from the server based on those dates, but when you click next/prev to fetch the new period of time events.
Anyone can help?

Here is the accepted answer: The "start" and "end" parameters are unix timestamps. You can have a controller action that takes the the timestamps like this:
public ActionResult GetAllCalendarEvents(double start, double end)
var startDate   = start.FromUnixTimestamp();
var endDate     = end.FromUnixTimestamp();
// Get your events into a list here
IEnumerable<SomeEventClass&gt; events = ...;
return Json(events.Select(evt =&gt; new
{
title           = evt.Title,
url             = evt.Url,
start           = evt.StartDate.ToISO8601(),
end             = evt.EndDate.ToISO8601(),
}), JsonRequestBehavior.AllowGet);
The extension methods I use above are as follows:
public static DateTime FromUnixTimestamp(this double timestamp)
var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp).ToLocalTime();
public static string ToISO8601(this DateTime date)
return date.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz");
Hope this helps.
Comment for this answer: Thank for the hint,  but how do I call it in the js form the calendar? When I click next there, will it call for the new start and end?  Sorry if this sounds stupid :)
Comment for this answer: I finally had the time to implement it, it works, nothing you need to add on the js part. The calendar will always send start and end for the current view!,  Thank you very much!
Comment for this answer: From the docs: http://fullcalendar.io/docs/event_data/events_json_feed/  The GET parameter names will be determined by the startParam and endParam options. ("start" and "end" by default).
The values of these parameters will be ISO8601 date strings (like 2013-12-01). For precise behavior, see the timezone docs.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:11/04/15', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<jquery><ajax><asp.net-mvc><fullcalendar>', 'Title': 'Jquery full calendar - get only current view events', 'ViewCount': 1627, 'id': 33521688, 'user_AboutMe': '<p>a beginner web developer </p>\n', 'user_AccountId': 5577838.0, 'user_DisplayName': 'AdrianD', 'user_Reputation': 279.0, 'user_Views': 40.0, 'user_id': 4420721.0}}