Event Calendar in MVC application Using jMonthCalendar(JQuery)
A good Jquery plugin is available as Event Calendar which can be download from following location.
http://www.bytecyclist.com/projects/jmonthcalendar/
or
http://code.google.com/p/jmonthcalendar/
I used it in one sample project with MVC and loaded certain events from the controller. Which can in return load from the Model. But for the time being in this sample i returned from the controller it self.
public ActionResult Events(string date)
{
MyEvents event1 = new MyEvents
{
EventID = 11 ,
StartDate = new DateTime(2009,04,01),
Title = "Meeting with Boss",
Description = "Meeting on product release",
CssClass = "Meeting",
URL= "/Home/EventDetails/11"
};
MyEvents event2 = new MyEvents
{
EventID = 12,
StartDate = new DateTime(2009, 04, 01),
Title = "Celebration",
Description = "Fathers birthday",
CssClass = "Birthday",
URL = "/Home/EventDetails/12"
};
string[] stringlist = new string[2];
stringlist[0] = event1.GetJSONResult();
stringlist[1] = event2.GetJSONResult();
return Json(stringlist);
}
For calling the events it did getJson call from the index page where the jMonthCalendar is shown. It will call one of the function the Controller and in return will get the array of the events which will then be sent to the jMonthCalendar. It will load the events. We can add the URL also so that when user clicks the event he will get the complete detail once again with the help of the controller
<script type="text/javascript">
$().ready(function() {
var options = {
height: 650,
width: 980,
navHeight: 25,
labelHeight: 25,
onMonthChanging: function(dateIn) {
$.getJSON("http://localhost:1511/Home/Events",
function(data) {
//Array of my events
var events = new Array();
//Loop and load all the events and load them into the array
$.each(data, function(i, item) {
var oResultData = eval('(' + item + ')');
var event = { "EventID": 5, "Date": oResultData.StartDate,
"Title": oResultData.Title, "URL": oResultData.URL,
"Description": oResultData.Description,
"CssClass": oResultData.CssClass
};
events.push(event);
});
//Load the events into the calendar
$.jMonthCalendar.ReplaceEventCollection(events);
$.jMonthCalendar.DrawCalendar(dateIn);
});
return true;
},
onEventBlockOver: function(event) {
return true;
},
onEventBlockOut: function(event) {
return true;
},
onDayLinkClick: function(date) {
return true;
},
onDayCellClick: function(date) {
return true;
}
};
var newevents = [];
$.jMonthCalendar.Initialize(options, newevents);
});</script>
Download the sample from following location
Here are the screen shot of the application.


Thanks!
Just the job! Is JSON the best way to do this? I don’t really know what it is and have never used it before
Jon
April 30, 2009 at 5:46 pm
Doing with JSON is not a problem and easiest method here. We can do data-interchange from XML or other methodology. But doing it with JSON is easy and simple. Now days it is popular and being used at various places. Also it is very simple to understand and use also
JSON is just a lightweight data-interchange format. If you see 2 or 3 sample on web for JSON you will get good idea of it.
Check the following sites
http://en.wikipedia.org/wiki/Json
http://www.json.org/
http://ascherconsulting.com/what/are/the/advantages/of/using/json/
A.Sethi
April 30, 2009 at 6:54 pm
I see now! Seems perfect and pretty straight forward. I was only thinking before this post that I wonder how I would pass server side data to the javascript! Keep up the good work!
Jon
April 30, 2009 at 7:53 pm
[...] Event Calendar in MVC application Using jMonthCalendar(JQuery … [...]
LDAP Data Interchange Format : Mildmay Monarchs
May 7, 2009 at 5:42 am
Hi!
I have just downloaded jMonthCalendar v1.2.2 and cannot get data to display on the calendar. The JSON is returning successfully and is looping in the JavaScript but nothing appears.
I also wonder how do you get it to appear straight away rather than onMonthChanging for example if you went to http://www.mydomain.com/events it would default to the month of the current date so how would you load the current month’s events?
Thanks
Jon
July 20, 2009 at 7:14 pm
I noticed that when you created a date in April, it turned out displaying in May. Did you find a solution for this issue?
Brian
September 30, 2009 at 7:57 pm
Actually in java script months starts from 0 not from 1 so when assigning the date of sending it to page as json we should subtract 1 from the month so that we can get correct month displayed
A.Sethi
October 4, 2009 at 4:50 pm
thanks
A.Sethi
April 30, 2009 at 8:23 pm