New Lounge Front-end (now with ASP.NET MVC and NHaml)
Wednesday, April 30 2008
Since taking over The Lounge I have been slowly refactoring it to my liking. Not that there was much wrong with it, but like most developers I am pretty opinionated in how I think something should be built. Most of what I have done has been in an effort to make a total rewrite of the front-end easier. The biggest change was refactoring the front-end and models to move as much logic as possible to the models and wrap tests around those models. I consider this a good practice and since I knew I wanted to re-write the front-end it was doubly important.
When it came time to start the rewrite I decided to go with ASP.NET MVC, even though it's in an early stage I couldn't imagine writing classic ASP.NET if I could do anything to avoid it. I also decided to go with NHaml for the UI to stay away from .aspx completely and because I am a big fan of the original Haml.
The re-write went very smooth and the site is now live, I know I am not the first site to go live with ASP.NET MVC, but it has to be at least one of the first ones. Especially one of the first ones that is an actual business and not just an experiment. I only ran into a couple issues along the way and they were easy to figure out.
The simplicity of these two technologies is a joy, for instance here is the controller action for showing a room:
public void Show(string id) { Room room = Room.GetRoomByCode(id); room.LoadVIPs(); RenderView("show", room); }
Thats about as simple as you get. (next version we will be able to drop the "show" in the RenderView, even better!)
Here is a excerpt from the view:
-foreach(TheLounge.Model.Vip vip in ViewData.Vips)
#roomdetail
%a{href=vip.Url,class="borderit"}
%img{src="../Content/images/vip/" + vip.Image, class="left"}
.viptitle
%a{href=vip.Url}
= vip.Title
.vipdesc
= vip.Bio
.clearleft
I love it. No controls, no viewstate, just simple web programming.
I am going to post a number of posts on things I learned about MVC and nHaml, especially about some best practices I learned in rails that I think apply very well to MVC.
-James
Comments
- #1 Joey Beninghove on 4.30.2008 at 10:12 PM
-
Hey James,
Did you go with the simpler ActiveRecord approach for your models or a more PI domain model/repository approach?
Looks like you're going with ActiveRecord, but was just curious...
BTW, site looks great!
- #2 James Avery on 4.30.2008 at 10:14 PM
-
I am actually using SubSonic but I worked it up to basically work like ActiveRecord.
Thanks!
- #3 Tim on 5.01.2008 at 7:57 AM
-
You actually said "classic ASP.NET" wow!
- #4 Andy on 5.01.2008 at 9:56 AM
-
We've been looking at using MVC. I'm glad to hear that it is worth using. Haven't done a whole lot with it yet but it sounds like I should start to.
- #5 Dan Hounshell on 5.01.2008 at 11:01 AM
-
James, the site looks and performs awesome. I can't wait to read some of those nitty-gritty articles!
- #6 David on 6.08.2008 at 2:53 PM
-
Hey james,
great to see a nhaml site out there. I am about to deploy a nhaml site too to iis. I am having issues with rendering my pages properly. How did you setup your site? did you use isapirewrite ?
- #7 James Avery on 6.08.2008 at 3:11 PM
-
I mapped all requests to the aspnet dll and everything worked fined. If you have problems after doing that shoot me an email and I will see if I can help out. (javery at this domain)
- #8 Andrew Peters on 7.21.2008 at 11:03 PM
-
Awesome stuff James!
- #9 Rich on 8.19.2008 at 11:20 PM
-
It's nice to see a live nhaml site! I am trying to build my own site using nhaml and subsonic. Can you provide a sample ASP.NET MVC nhaml and subsonic project? Thanks.

