Header background image for AlwaysMoveForward.com
Software

My MVC Experiement - Calendar

By Arthur Correa • Author

Ok so I had the basics of an ASP.NET MVC blog site up and running.  I had my data layer written using LINQ, I had my business layer defined with Services and Entities, and I was starting to build my MVC code on top of those.  I had figured out how and where I wanted to do Ajax, and how to page my result sets.  Now I decided I wanted to implement a calendar.

 Now if I was doing a Web Forms project I'd just grab a Calendar control and drop it onto the page.  Then tell it what dates to highlight server side.  Unfortunately I didn't have that option. 

The first thing I did was go out and look for some sort of open source/freeware sort of control that did what I wanted it to do.  I managed to find one provided by Yahoo here.  I started to use it, and it was sort of working.  I got it on the page, I managed to start styling it with CSS, and I was starting to set the dates on the calendar. 

I found it a little bit more than I needed though.  It's a pretty powerful calendar, and I'm sure it works great for a lot of people.  However I was finding it a bit difficult to work with, largely because it was more powerful than I needed it to be.

So I decided I'd try to write my own.  I was dreading the task to be honest.  How do I know how many rows I need?  How would I know what day of the week to start the month on?  What is the best wa to show non month dates?

Man was I wrong.  I ended up writing my calendar control in about 2 or 3 hours.  Sure its not uber powerful, sure its kinda tailored to my site.  However it does what I need it to do for a blog site.  It shows everything the way I want it, and it is skinnable via CSS. 

This is a great example of how I'm liking ASP.Net MVC and its impact on me.  When I first started this software project I didn't want to do MVC because of all the extra work I would have to do because MVC didn't have all of Web Forms' powerful controls.  But I'm finding that having to build those elements on my own with just HTML and CSS is not only a good challenge, its breaking my reliance on those Web Form's controls.  Which really isn't a bad thing in my opinion.