Creating a ASP MVC CRUD application

A few years ago, creating a web application with create, read, update and delete (CRUD) functionality with traditional ASP or ASP.NET web forms could become cumbersome. In traditional ASP, developers were left with mixing presentational HTML markup with server-side Visual Basic script, which made creation and maintenance of applications difficult.

When ASP.NET web forms debuted, it shifted the paradigm where developers could at least separate presentational HTML markup from server-side business logic with their preferred object-oriented language (Visual Basic or C#.NET). However, web forms came with out of the box web controls that cornered developers into data controls which often felt bloated and made HTML output rendered by the application server (Internet Information Services) hard to debug.

With the radical shift in development with ASP MVC developers can create web applications like CRUD relatively easy and separate behaviors of concern. Developers have complete control over HTML markup, and the ability to separate classes based on their intended behaviors.

In the following tutorial, we’ll see how we can create a simple applicant system with ASP MVC. We’ll explore how we can either use the existing HTML markup scaffolding Microsoft provides, or create our own. We’ll see a glimpse of the new database access framework known as entity framework and how it can alleviate some of the common mistakes developers using in-line structured query language (SQL) make. We’ll understand how Razor web page views communicate via implicit GET and explicit POST commands. Lastly, we’ll start to see how ASP MVC delivers separation of concerns throughout an application.

If you would like to create an application such as this one, please do follow along in this step-by-step tutorial.

Download Project Files
Source Files


Before beginning we need to make sure we have the following software installed and operational:

  1. Microsoft .NET framework or higher
  2. ASP MVC 4 or higher
  3. Microsoft Visual Studio
  4. Microsoft SQL Server Management Studio
  5. Make sure to install the local database service and management studio product

Once you have downloaded and installed these applications, open Visual Studio by following these steps:

  1. From the desktop, left click Start button
  2. In the search field, type visual studio
  3. Left click to select Visual Studio

Start Menu VS 13

Creating the project

From Visual Studio, follow these steps:

  1. From the main menu, choose File : New : Project

File New Project

  1. In the New Project window:
    1. From the left pane, leave Visual C# as selected
    2. From the top combo box, choose .NET Framework 4.5.1
    3. From the main window, choose ASP.NET Web Application

Select New Project 1

  1. Next, while in the New Project window, at the bottom:
    1. In the name field, type Applicant
    2. In the location field, choose root of C:\
    3. In the solution field, should be auto filled with the same name as the name field (1.)

Select New Project 2

  1. Lastly, while in the New Project window, at the bottom right:
    1. In the check box for Create directory for solution, leave checked
    2. In the check box for Add to Source Control, leave unchecked
    3. Once finished, click OK

Select New Project 3

Note: Regarding source control, once we have this project finished, pushing the files into a source control repository such as Team Foundation Server (TFS), Subversion, GitHub or CodePlex should be a straightforward task.

In the next window, choose (1) MVC and click (2) OK:

Select New Project 4

Once Visual Studio has completed creating the project, we should see from the right side in solution explorer we have a functional web application created with the appropriate folder structure needed for MVC. Go ahead and press F5 on the keyboard to ensure the project builds and launches a web page as shown below:

Default Website

Entity framework with MVC applications

In the latest versions of the .NET framework, Microsoft has provided a new and more robust approach to data access with ASP MVC applications called entity framework. Entity framework aims to solve some of the common problems associated to data access retrieval and submission from ASP MVC application including but not limited to:

  1. Performance of complex queries: if your application is using complex stored procedures with complex business logic, it may be a worthwhile exercise to determine if using entity framework can speed up the query operation and make the overall query structure easier to write and understand.
  2. Native support of database operations: much like Active Data Objects (ADO), entity framework has native methods to perform common database operations such as selecting, filtering, sorting, adding, updating and deleting data from a database
  3. Native support of parameterized queries: with traditional ASP applications and ADO, we have to explicitly parameterize queries that deal with insertion of data into a database from an application to prevent the use of structured query language (SQL) injection attacks. With entity framework, parameterized queries are natively supported

For the purposes of this tutorial, we’ll be using entity framework and a deeper dive using entity framework will be covered later.

We'll continue next with creating our database.