Click here to Skip to main content
11,705,212 members (49,732 online)
Click here to Skip to main content

Tagged as

Understanding ASP.NET MVC (Model View Controller) Architecture for Beginners

, 14 May 2012 CPOL 509.4K 228
Rate this:
Please Sign up or sign in to vote.
Learning ASP.NET MVC (Model View Controller) architecture and fundamentals for beginners

Introduction

This article is intended to provide basic concepts and fundamentals of ASP.NET MVC (Model View Controller) architecture workflow for beginners.

“M” “V” “C” stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner than the traditional ASP.NET web development. Web applications developed with ASP.NET MVC are even more SEO (Search Engine) friendly.

Developing ASP.NET MVC application requires Microsoft .NET Framework 3.5 or higher.

MVC Interaction with Browser

Like a normal web server interaction, MVC application also accepts requests and responds to the web browser in the same way.

Inside MVC Architecture

The entire ASP.NET MVC architecture is based on Microsoft .NET Framework 3.5 and in addition uses LINQ to SQL Server.

What is a Model?

  1. MVC model is basically a C# or VB.NET class
  2. A model is accessible by both controller and view
  3. A model can be used to pass data from Controller to view
  4. A view can use model to display data in page.

What is a View?

  1. View is an ASPX page without having a code behind file
  2. All page specific HTML generation and formatting can be done inside view
  3. One can use Inline code (server tags ) to develop dynamic pages
  4. A request to view (ASPX page) can be made only from a controller’s action method

What is a Controller?

  1. Controller is basically a C# or VB.NET class which inherits system.mvc.controller
  2. Controller is a heart of the entire MVC architecture
  3. Inside Controller’s class action methods can be implemented which are responsible for responding to browser OR calling views.
  4. Controller can access and use model class to pass data to views
  5. Controller uses ViewData to pass any data to view

MVC File Structure & File Naming Standards

MVC uses a standard directory structure and file naming standards which are a very important part of MVC application development.

Inside the ROOT directory of the application, there must be 3 directories each for model, view and Controller.

Apart from 3 directories, there must have a Global.asax file in root folder, and a web.config like a traditional ASP.NET application.

  • Root [directory]
    • Controller [directory]
      • Controller CS files
    • Models [directory]
      • Model CS files
    • Views [directory]
      • View aspx/ascx files
    • Global.asax
    • Web.config

ASP.NET MVC Execution Life Cycle

Here is how MVC architecture executes the requests to browser and objects interactions with each other.

A step by step process is explained below [Refer to the figure as given below]:

Browser Request (Step 1)

Browser request happens with a specific URL. Let’s assume that the user enters URL like: [xyz.com]/home/index/

Job of Global.asax – MVC routing (Step 2)

The specified URL will first get parsed via application_start() method inside Global.asax file. From the requested URL, it will parse the Controller, Action and ID.

So for [xyz.com]/home/index/:

  • Controller = home
  • Action = index()
  • ID = empty — we have not specified ID in [xyz.com]/home/index/, so it will consider as empty string

Controller and Action methods (Step 3)

MVC now finds the home controller class in controller directory. A controller class contains different action methods,

There can be more than one action method, but MVC will only invoke the action method which has been parsed from the URL, its index() in our case.

So something like: homeController.index() will happen inside MVC controller class.

Invoking action method can return plain text string OR rendered HTML by using view.

Call to View (Step 4)

Invoking view will return view(). A call to view will access the particular ASPX page inside the view directory and generate the rendered HTML from the ASPX and will respond back to the browser.

In our case, controller was home and action was index(). So calling view() will return a rendered HTML from the ASPX page located at /views/home/index.aspx.

This is it, the whole process ends here. So this is how MVC architecture works.

History

  • 26th January, 2010: Initial post

License

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

Share

About the Author

kiran dangar
Software Developer (Senior) Gateway Technolabs Pvt. Ltd
India India
Having 4+ years of Technical Experience in asp.net,c#.net, SQL Server 2008,AJAX, XML,JQuery, JavaScript, .net framework, WCF, WPF/Silverlight,SSIS, SSRS, asp.net MVC.

While not working loves Photography and bike riding. Playing computer games are the best stress buster for him Smile | :)

You may also be interested in...

Comments and Discussions

 
Generalnice article Pin
K I R T I8-Apr-15 23:58
professionalK I R T I8-Apr-15 23:58 
GeneralMy vote of 1 Pin
soufiane24-Feb-15 4:35
membersoufiane24-Feb-15 4:35 
GeneralRe: My vote of 1 Pin
kiran dangar9-Jul-15 5:35
memberkiran dangar9-Jul-15 5:35 
QuestionGood explanation Pin
Its Tinku3-Feb-15 20:29
memberIts Tinku3-Feb-15 20:29 
GeneralMy vote of 1 Pin
SumitSE8-Sep-14 5:15
memberSumitSE8-Sep-14 5:15 
GeneralRe: My vote of 1 Pin
kiran dangar9-Jul-15 5:36
memberkiran dangar9-Jul-15 5:36 
GeneralMy vote of 3 Pin
Emmanuel Ponciano8-Sep-14 3:36
memberEmmanuel Ponciano8-Sep-14 3:36 
QuestionGood Pin
Jagbir Saini14-May-14 1:20
professionalJagbir Saini14-May-14 1:20 
QuestionXx Pin
rfid20097-Apr-14 16:34
memberrfid20097-Apr-14 16:34 
GeneralMy vote of 1 Pin
sagar kumar parida6-Feb-14 2:58
membersagar kumar parida6-Feb-14 2:58 
GeneralRe: My vote of 1 Pin
kiran dangar9-Jul-15 5:36
memberkiran dangar9-Jul-15 5:36 
Question5 * for this article Pin
Monibrata Bhattacharjee3-Feb-14 18:53
memberMonibrata Bhattacharjee3-Feb-14 18:53 
GeneralMy vote of 1 Pin
vimalmca1016-Sep-13 23:26
membervimalmca1016-Sep-13 23:26 
GeneralGood Pin
Bhushan Gupta1-Sep-13 6:25
memberBhushan Gupta1-Sep-13 6:25 
GeneralMy vote of 4 Pin
Antariksh Verma27-Aug-13 21:40
professionalAntariksh Verma27-Aug-13 21:40 
Newscontent is good Pin
houzhimin27-Aug-13 16:47
memberhouzhimin27-Aug-13 16:47 
GeneralMy vote of 5 Pin
Balasubramanian T18-Aug-13 3:16
memberBalasubramanian T18-Aug-13 3:16 
GeneralRe: My vote of 5 Pin
jagmohan8722-Aug-13 1:03
memberjagmohan8722-Aug-13 1:03 
GeneralThank you Pin
vj21soni16-Aug-13 3:50
membervj21soni16-Aug-13 3:50 
GeneralMy vote of 5 Pin
Rajesh Duraisamy28-Jul-13 20:57
groupRajesh Duraisamy28-Jul-13 20:57 
GeneralMy vote of 2 Pin
Shashi kant Tiwary16-Jul-13 4:17
groupShashi kant Tiwary16-Jul-13 4:17 
GeneralMy vote of 4 Pin
RajeshKumar Sugumar15-Apr-13 20:51
memberRajeshKumar Sugumar15-Apr-13 20:51 
QuestionExcellent article Pin
DalePres28-Mar-13 5:52
memberDalePres28-Mar-13 5:52 
GeneralMy vote of 3 Pin
George L. Jackson12-Mar-13 4:06
memberGeorge L. Jackson12-Mar-13 4:06 
GeneralMy vote of 2 Pin
Enrique Albert4-Mar-13 22:57
memberEnrique Albert4-Mar-13 22:57 
SuggestionASP.net MVC Interview Questions Answers Pin
mitu sinha12-Jan-13 6:07
membermitu sinha12-Jan-13 6:07 
QuestionMy vote of 4 Pin
magiccoder1-Jan-13 23:56
membermagiccoder1-Jan-13 23:56 
GeneralMy vote of 2 Pin
Member-394866314-Nov-12 22:51
memberMember-394866314-Nov-12 22:51 
GeneralRe: My vote of 2 Pin
rohan garud10-May-13 23:21
memberrohan garud10-May-13 23:21 
GeneralMy vote of 3 Pin
alexalexalex190723-Oct-12 4:41
memberalexalexalex190723-Oct-12 4:41 
Questionits good Pin
waseem-ricky29-Sep-12 21:04
memberwaseem-ricky29-Sep-12 21:04 
GeneralMy vote of 4 Pin
Pravin028-Sep-12 3:10
memberPravin028-Sep-12 3:10 
GeneralGreat Description Pin
gabapradeep15-Sep-12 22:11
membergabapradeep15-Sep-12 22:11 
QuestionSome error on the directory name? Pin
irnbru12-Sep-12 23:56
memberirnbru12-Sep-12 23:56 
AnswerRe: Some error on the directory name? Pin
kiran dangar13-Sep-12 19:18
memberkiran dangar13-Sep-12 19:18 
Questionthanks Pin
deepak3dart12-Sep-12 19:12
memberdeepak3dart12-Sep-12 19:12 
GeneralMy vote of 4 Pin
Faithcz13-Aug-12 3:22
memberFaithcz13-Aug-12 3:22 
GeneralMy vote of 3 Pin
RGhaywat2-Jul-12 19:37
memberRGhaywat2-Jul-12 19:37 
GeneralMy vote of 4 Pin
crcklssp5-Jun-12 19:43
membercrcklssp5-Jun-12 19:43 
GeneralRe: My vote of 4 Pin
kiran dangar6-Jun-12 3:08
memberkiran dangar6-Jun-12 3:08 
GeneralMy vote of 5 Pin
Muhammad Hussain Tabassum28-May-12 2:33
memberMuhammad Hussain Tabassum28-May-12 2:33 
GeneralRe: My vote of 5 Pin
kiran dangar30-May-12 3:12
memberkiran dangar30-May-12 3:12 
GeneralMy vote of 5 Pin
meeram39524-May-12 7:02
membermeeram39524-May-12 7:02 
GeneralRe: My vote of 5 Pin
kiran dangar30-May-12 3:13
memberkiran dangar30-May-12 3:13 
GeneralMy vote of 3 Pin
amitgajjar23-May-12 19:30
memberamitgajjar23-May-12 19:30 
GeneralMy vote of 3 Pin
LFD-Mike23-May-12 6:03
memberLFD-Mike23-May-12 6:03 
GeneralMy vote of 5 Pin
manoj kumar choubey16-May-12 21:23
membermanoj kumar choubey16-May-12 21:23 
GeneralRe: My vote of 5 Pin
kiran dangar16-May-12 22:21
memberkiran dangar16-May-12 22:21 
GeneralRe: My vote of 5 Pin
MadhaviLatha.Bathini21-Apr-13 1:14
memberMadhaviLatha.Bathini21-Apr-13 1:14 
GeneralMy vote of 5 Pin
lavikgupta8-May-12 23:32
memberlavikgupta8-May-12 23:32 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 14 May 2012
Article Copyright 2010 by kiran dangar
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid