Click here to Skip to main content
12,997,060 members (42,287 online)
Click here to Skip to main content
Add your own
alternative version


10 bookmarked
Posted 26 Feb 2010

How to ASP.NET MVC (Article 1)

, 14 Mar 2010
Rate this:
Please Sign up or sign in to vote.
Develop a sample application using Asp.Net MVC

Download - 700 B
Download - 307.28 KB



Today I will discuss about how can we develop a simple Asp.Net MVC Application. As a first article about Asp.Net MVC i will today discuss about a very simple Application development. 


  MVC:<o:p />

The Model View Controller (MVC) architectural pattern separates an application into three main components:<o:p />

·                  Models: Model objects are the parts of the application that implement the domain logic. Often, model objects also retrieve and store model state in a database.<o:p />

·                  Views: Views are the components that display the application's user interface (UI). Typically, this UI is created from the model data. An example would be an edit view of a Products table that displays text boxes, drop-down lists, and check boxes based on the current state of a Product object.<o:p />

·                  Controllers: Controllers are the components that handle user interaction, manipulate the model, and ultimately select a view to render the UI. In an MVC application, the view only displays information; the controller handles and responds to user input and interaction.<o:p />




 The ASP.NET MVC framework is a lightweight, highly testable presentation framework that is integrated with existing ASP.NET features, such as master pages and membership-based authentication.<o:p />

You must have the following items to develop mvc application<o:p />

o         Microsoft Visual Studio 2008 SP1<o:p />

o        Microsoft ASP.NET MVC 1.0 (visit for downloading )<o:p />

o        Microsoft  SQL 2005 or Microsoft  SQL 2008 (Express edition or above)<o:p />

o        Test database (Create a database named ‘Test’ and then run ‘test.sql’)<o:p />


Database and Script:

    Before building/running this application please create a database named "Test" and run the "tables.sql" script.

Build a simple ASP.NET MVC Application<o:p />

1.       File -> New -> Project -> Asp.Net MVC Web Application


2        Allow with not select to create Unit test Project


3.        Solution Explorere will be like that 



Now I would like you to give a little description of the different folders use in Solution:


Content: Content hold the necessary Style sheet file<o:p />

Controller:  Contains the Controller class. This is the entry point of any operation. For any user action, controller listen the action and process that action through ‘Model’ and finally return a ‘View’ associated with this action.<o:p />

Script: Contains the related javascript used by the application<o:p />

Views:  Views are returned by Controller. So for every controller like ‘HomeController’ there will be created a ‘Home’ in views and ‘AccoutController’ there will be created a ‘Account’ as well. There is also a folder in “Views” that is “Shared”. This “Shared” contains the necessary Master Pages and user controll.


That’s all the little description about the folder structure used by Mvc.


4.       Right click the Model folder and add a new “ Entity DataModel”


5.       Create Test.edmx with two tables Customer And Orders (Scripts is attached with source code)


<o:p>    Right click the “Controller” and Add a “Controller” named “CustomerController”. Check the “Add

      action methods for Create, Update, and Details scenarios” 

<o:p />

<o:p> <o:p>

 Now Modify CustomerController.cs like that:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using MvcApplication1.Models; 
namespace MvcApplication1.Controllers
    public class CustomerController : Controller
        // GET: /Customer/
        TestEntities entities = new TestEntities();

        public ActionResult Index()

            return View(entities.Customer);
        // GET: /Customer/Details/5

        public ActionResult Info(string id)
            var information = entities.Customer.Where(a => a.CustomerID == id).First();
            return View(information);

 As today is our first Article so We will work only Selecting a list of customers with details. There have to need a study about the internal functionalities and architecture. So if you want ot know details please visit Here i have used the TestEntities class. The different methods work actually how you want to interact with Model and finally you will get a View() like ActionResult Index() will return a Customer entity which will be the index page of Customer View.

public ActionResult Info() will return a perticular Customer Info using a ID


 Now 7. Right click inside the "public ActionResult Index()" method and Add View  selecting the check box "create a strongly-typed view", and select "Data Class" as "Customer" and "View Contenet" as "List"

       8. You will see a page "Index.aspx" has been added to "Views\Customer\"

       9. Right click also inside the "public ActionResult Info(string id)" method and add View  selecting the check box "create a strongly-typed view", and select "Data Class" as "Customer" and "View Contenet" as "Details" 

Thats all. You will get all the customer in Index.aspx page with Details Information. You need just a little adjustment in Index.aspx and Info.aspx page as "Create New" will not work as we did not use the " public ActionResult Create()" method. So modify the Page as i did in source code.


When will run the application, you will get all the customer information and when you will click the Details link, you will find details information about that customer.


<o:p />

Points of Interest  

Did you learn anything interesting/fun/annoying while writing the code? Did you do anything particularly clever or wild or zany?


Keep a running update of any changes or improvements you've made here.  


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior) Secure Link Services Ltd
Bangladesh Bangladesh

I am a Microsoft certified Technology specialist (.net framework 2.0 web)
I like to do programming in Microsoft Platform.
My Favorite language is C# and VB.Net

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
sunilkgupta20-Mar-12 2:24
membersunilkgupta20-Mar-12 2:24 
GeneralMy vote of 1 Pin
Ranjan.D17-Mar-10 22:17
memberRanjan.D17-Mar-10 22:17 
General[My vote of 1] Not enough detail Pin
Mark Nischalke15-Mar-10 3:14
mvpMark Nischalke15-Mar-10 3:14 
GeneralMy vote of 1 Pin
Juraj Suchan14-Mar-10 23:58
memberJuraj Suchan14-Mar-10 23:58 
GeneralMy vote of 1 Pin
paragme28-Feb-10 19:43
memberparagme28-Feb-10 19:43 
GeneralRe: My vote of 1 [modified] Pin
Juraj Suchan14-Mar-10 23:58
memberJuraj Suchan14-Mar-10 23:58 
GeneralMy vote of 1 Pin
Seishin#27-Feb-10 13:36
memberSeishin#27-Feb-10 13:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170622.1 | Last Updated 15 Mar 2010
Article Copyright 2010 by arif_uap
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid