Build a Simple Blog Engine with ASP.NET MVC and LINQ - Part 1
Last week Microsoft released first CTP of ASP.NET 3.5 Extensions which includes first public version of ASP.NET MVC Framework. There have been lots of good resources about this MVC Framework on the web as tutorials, blog posts and web casts.
I'm getting free from the book and would have some free time after this to spend on some interests. I also promised to write more about new technologies on this blog and now I want to begin the progress by ASP.NET MVC Framework and its related stuff because I'm going to get serious with this framework.
I want to write a set of blog posts about ASP.NET MVC Framework to build a simple blogging engine based on MVC and LINQ in .NET 3.5 and show you all the steps in detail then extend the discussion to some more-in-depth topics. I haven't written this application completely and will write it in parallel with these blog posts (dude, where is my stolen time?!).
Such a sample application is provided by ASP.NET MVC toolkit but there isn't a description about it yet (or at least I couldn't find any!). But why I'm doing this while there are some other tutorials with same approach? In my opinion the learning curve of this MVC Framework consists of a workflow progress of some steps that should be followed and the major thing is this. Building this simple blogging engine and describing its process would be a very good example for ASP.NET MVC Framework.
So here is the first post of this series that I want to finish them in a few weeks and is an introduction with some basic information.
What is MVC?
Yes, what is that?! Others have described this better than me but I repeat it in my words.
MVC (Model View Controller) is a methodology to build application based on the idea of dividing the implementation into three roles: Model, View and Controller.
Let's take a second look at above sentence (like mathematic books!). From the above sentence we believe that MVC is a methodology not a technology so it has been used before Microsoft adapts it to ASP.NET! I persisted on this because saw some guys who thought it's a technology that is designed for ASP.NET specifically.
I also need to introduce above three roles in a nutshell:
- Model: This is the role to maintain the state. Usually these are classes that represent data in database.
- View: The second role displays the data in user interface to end users. This may be a set of user interface elements like TextBoxes, editors and buttons.
- Controller: The last role is responsible to interact with user inputs and handling it. In fact controller is where you implement the actual logic to handle what user has asked for.
The MVC has become a very good methodology to design applications that rely on data interactions. The most important benefit of MVC is the ability to unit test the application easily. Because you can unit test an MVC application via its controllers and apply a TDD workflow (Red-Green-Refactor) easily.
I don't discuss more about the MVC and just refer you to Scott Guthrie's post about it and its description on Wikipedia that would be sufficient to get you started.
What is ASP.NET MVC Framework?
The ASP.NET MVC Framework is the Microsoft's adoption of MVC for its ASP.NET technology for version 3.5 where it provides features required to build a web application based on MVC.
ASP.NET MVC Framework is currently under construction and only one public release is available for download as a part of ASP.NET 3.5 Extensions CTP.
Once you download and install this package, you can get benefit of different pieces of ASP.NET 3.5 Extensions and it automatically installs some project templates for you on Visual Studio 2008.
Along this download package, there is an MVC toolkit package available for download that provides some helpful tools for your MVC development. I may use them in my posts as well.
Basics of KBlog
For this post series, I'm going to build a simple sample blogging tool that I call it KBlog. This blogging engine will be built on top of some considerations that would be described here.
This blogging engine supports blog posts, comments and categories. A blog post can have only one category and as many comments as possible. This blog engine is for single user only and has some URL patterns for public and private pages.
I'll use SQL Express for my database and for first steps, I fill this database manually and after finishing my discussion with public pages, I'll jump into details of administration pages where user can enter data.
Create the Project
Obviously the first step is to create a project in Visual Studio. Under Web category, you can choose "ASP.NET MVC Web Application" project item which should be available after installing ASP.NET 3.5 Extensions CTP. I name my project KBlog!
After this, Visual Studio generates a project for you with the pre-defined template and structure.
Getting Started
At the first glance Visual Studio generates an ASP.NET web application project for you with a simple structure.

Taking a look at this project, you believe that there are some references for the project and one important reference is to System.Web.Extensions assembly. There are also four folders available including Content, Controllers, Models and Views.
- Content folder is just for a default CSS stylesheet file for default look and feel of the site.
- Controllers folder is responsible to hold controller classes.
- Models folder is responsible to hold model classes.
- Views folder is responsible to hold view files and contains some folders that include ASPX and master files.
As you see, Controllers, Models and Views are more important for us here. While, they're generated to hold controllers models and views but this isn't a rule and you can replace them with your own structure.
Beside these folders, there are some well-known ASP.NET files that of course have some extra definitions that I'll describe later.
There is a point to mention here about Default.aspx file and as mentioned in the content of this file, you shouldn't remove the file to let IIS activate MVC for the application when user navigates to this page.
That's enough for now! Step by step, I'm going to add my implementation to this project in the upcoming posts.
[advertisement] Axosoft OnTime 2008 is four developer tools in one: bug tracking, project wiki, feature management, and help desk. It manages your development process so developers can focus on coding. Installed or Hosted – Free Single-user license -- Free 30-day team trial.
2 Comments : 12.16.07
Feedbacks
Hi Keyvan,
Thanks for helping the community. I am looking forward for more tutorials from your side.
Pl. blog something related to upcoming dynamic languages like IronRuby and IronPython also.
I could not find any link on your side to read your blogs. I just reached here via DotNetKicks.
Pl. make a link available for your recent Blogs. How will one come to know, when your next tutorial is published.
Thanks
IronRuby

#1
Dave Burke
12.16.2007 @ 2:52 PM
This is good stuff, Keyvan! I'll be looking forward to the rest of the series.