Today’s article is going to be one of many, or at least a few, that take a look at building an application using the new ASP.Net MVC Beta. I wanted to do this in a small series so we can look at each phase of the application in a decent amount of detail while keeping the length appropriate for a blog post.


This first part isn’t actually going to crack the lid on MVC just yet but we are going to look at a few things today.

  1. What is MVC and specifically what does ASP.Net MVC look like?
  2. What will the goals of our application be? What features will it have?
  3. What will our database structure look like?

What is MVC Anyway?

Model-View-Controller is a design pattern that separates business logic from user interface logic. This separation allows for easier maintenance of the application. The models deal with the data and business rules that manipulate the data. Views represent the user interface and logic that handles user interaction such as mouse clicks and keyboard input. Finally, controllers manage all communication between models and views. In an ideal implementation models don’t know anything about views and vice versa, the controllers handle all of this.


What is ASP.Net MVC?

“ASP.NET MVC enables you to build Model View Controller (MVC) applications by using the ASP.NET framework. ASP.NET MVC is an alternative, not a replacement, for ASP.NET Web Forms that offers the following benefits:”

  • Clear separation of concerns
  • Testability – support for Test-Driven Development
  • Fine-grained control over HTML and JavaScript
  • Intuitive URLs

From ASP.Net MVC WebSite


What Do We Want Our Application To Do?

Planning is a critical phase of application development. Without proper planning and defining of goals and features “scope creep” can come in and drive your project off course. Also, if planning is not done up front, and done correctly, you can find yourself with a mess that is hard to modify and/or maintain over time.


We are only going to take a moment to define some features for our application since it will be pretty basic for this tutorial.

  1. Manage a list of tasks
  2. Tasks can have multiple todo items
  3. Tasks can be attached to milestones to set deadlines and measure productivity

So our application will cover 3 main areas; Milestones, tasks, and to do items.


The Database is Your Foundation

The schema of your database is like the foundation of a house. If built correctly, the house will be solid and even though you may do renovations, even extensive ones, your foundation will continue to support your house. In the same respect if you get the foundation wrong your house might just collapse under its own weight and making changes down the road might just do it in.

In the same way, the stability of your application depends on it’s foundation, your database. We are going to look at the tables that will support our application.

The Milestones table: 

   1: CREATE TABLE Milestones 
   2: (
   4:   Name VARCHAR(100) NOT NULL,
   5:   Description VARCHAR(255) NOT NULL,
   6:   CreationDate DATETIME NOT NULL,
   7:   Deadline DATETIME NOT NULL,
   8:   CompletionDate DATETIME NULL,
   9:   IsComplete BIT NOT NULL DEFAULT 0
  10: )

We already said that we want milestones to manage deadlines and tell how well we are doing at meeting those deadlines. Obviously we are going to keep this pretty basic, but we have a name and description for the milestone but also we are going to define the date the milestone was created, the deadline when it needs to done, and then we will keep track of the data it was actually completed whether that is sooner or later than the deadline to gives an idea about our performance.

The Tasks table:

   1: CREATE TABLE Tasks 
   2: (
   4:   Name VARCHAR(100) NOT NULL,
   5:   Description VARCHAR(255) NOT NULL
   6: )

This table defines our tasks. Basically a task represents something that we want to get done and contains a bunch of smaller to do items. This is pretty basic. Just an id, name, and description.


An example of a task might be to clean up your yard. This task would involve a number of smaller items to complete to clean the entire yard. We’ll take a look at some of those to do items when we get to that table.


The TodoItems table:

   1: CREATE TABLE TodoItems 
   2: (
   4:   Name VARCHAR(100) NOT NULL,
   5:   Description VARCHAR(255) NOT NULL,
   6:   IsComplete BIT NOT NULL DEFAULT(0),
   7:   TaskId INT NOT NULL REFERENCES Tasks(Id)
   8: )

Using our example of cleaning up your yard as a task there would be several todo items involved in completing that task. For example some todo items would be: mow the grass, rake the leaves, trim the trees and bushes, etc.


Our to do items have an id, name, description, a flag indicating whether or not it is complete, and a task id to tie it to the task.


The MilestoneTasks table:

   1: CREATE TABLE MilestoneTasks 
   2: (
   4:   MilestoneId INT NOT NULL REFERENCES Milestones(Id),
   5:   TaskId INT NOT NULL REFERENCES Tasks(Id)
   6: )

I could have added a MilestoneId to the Tasks table but attaching tasks to milestones is going to be optional in our applications meaning we may want to define some tasks that we don’t want to be on any milestones. Some people feel it is acceptable to have a NULL foreign key while others prefer to use another table to keep their implementation “pure”. It is up to you which you want to use. Both ways will work.


A real world example of this might be tasks that you need to assign to team members but don’t want to show up in any of the milestones that the client see.


This table allows tasks to be tied to milestones and has the flexibility to allow tasks to be assigned to many milestones.


What We Have So Far

So at this point we have established what MVC and ASP.Net MVC are, what we want our application to accomplish, and a solid database schema that will support our application and be flexible if we need to make changes in the future.


In the next article we’ll look at setting up out ASP.Net MVC application in Visual Studio and look at the Model portion of our application.


The author is Justin Bezanson from GeekDaily.

Tags :

5 Responses to “Working With ASP.Net MVC Part 1”

  1. MenoRikey

    Said on November 26, 2008 :

    when is part 2 coming?

  2. Amit

    Said on November 27, 2008 :

    I have just talked to justing and his reply is this:

    “Should have the next part ready soon. I have been working on it this week.”

    Well, I hope it will be sooner :)

  3. Justin

    Said on November 28, 2008 :

    I’m just putting the finishing touches on it. Should be done soon.

  4. MenoRikey

    Said on November 29, 2008 :

    looking forward to it.

  5. William

    Said on February 27, 2011 :

    Can you provide the entire source code for this project? I was trying to follow your tutorial but got lost in part 2. You don’t really mention where/how each thing is created. I truly want to learn MVC and thought that your project was a good starting point.

    Thank you,

Post a Comment