I have been working with ASP.NET MVC 2.0 for the last couple of months, 6 or so and the thing that I love the most about ASP.NET MVC is the fine grained control you have over the bits of your website, and it all feels like you are still working on a website. Lets be honest here for a moment, developing web applications with webforms feels unnatural and unwieldy and you always have this sense of it not being a “real” web application but rather some leaky abstraction of Windows Forms. ASP.NET MVC changed this perception a bit, by first dumping the whole page-life cycle and then by removing the whole page behind architecture. Instead you now have a very clear separation of concerns, with html being kept in views and your code is defined inside controllers and models. Controllers are small pieces of code that give views their content and you can specify whether a view is strongly typed or not, in which case when you use the Model keyword you gain access to a particular model’s properties or methods. The general rule is that controllers should be skinny and models should be fat. Models are the business logic of the application and contain items such as your interfaces and classes. Enough about what ASP.NET MVC is for now.
ASP.NET MVC 2 uses the Webform rendering engine and ASP.NET MVC 3 uses the Razor rendering engine. You can read more about the Razor view engine on Scott Gu’s blog, but essentially it boils down to is the way in which dynamic content and html is rendered and how your view engine deals with it.
Today I started reading up on ASP.NET MVC 3 and Razor, starting here because I wanted to get a better understanding of how layouts work in Razor and also how I could leverage some of its cool functionality specifically for a CMS. Before I continue discussing how I could see myself building a CMS using Razor, I want to define what I would want from a CMS and what I would want it to do. Consider this my requirement statement, my way of defining the nature and functionality of the CMS.
I want a CMS that is flexible enough to handle multiple page layouts without having to create static pages. In other words I want to create a CMS that allows me to add pages from scratch without having any static views in place. I just want to be able to create pages using different templates. So if my only view is the home view, then every subsequent page that I add will essentially be part of a ViewResult within the HomeController, and if pages are nested the ViewResult should reflect that. A page can have a parent or child page, nth levels deep. The basic workflow for adding a page to a CMS could be:
- Select a page Template
- Select a layout
- Populate regions within layout with content
- Save the page
Apart from this basic functionality the CMS should provide a way to integrate “datasets” or strongly typed data items into a page, style the data items and provide cascading pages if required without the CMS having to know anything about the data item it is cascading. If you have a product and it has several entities associated to it then you might want to create separate pages based on those entities, but then it means you have to specify the page and page layouts for the cascading items. It also depends on what type of layout that data item has.