In this article you will learn some basic concepts of MVC Architecture.
So what is MVC ?
- An Architectural design principle that separates the components of a Web Application.
- This separation gives you more control over the individual parts of the application , which lets you more easily develop , modify and test them.
- Three main components : The Model, The View, The Controller.
Models, Views, and Controllers
- Model — Model holds application data , data access logic.
- View — Markup and content that is returned to the browser
- Controller—Fires off some logic in response to a web browser request it listens incoming request from the browser manipulate the model data prepare the view to display in response to the web browser.
- Reason 1 : First reason to choose ASP .NET MVC is separation of concern which provides more understandable , rich and highly efficient design that makes it easy to work on .
- Reason 2 : to choose ASP.NET MVC for development is more effective control as user thinks that to control the html page is a tough job but in case of MVC it is not so as it provide effective control on html pages.
- Reason 3 : Third reason to choose MVC along with ASP.NET is that provide development along with testing and on the other hand when user is developing application in ASP.NET only then user cant do so . This solid reason helps user to overcome the unexpected outcome of developed application while developing it.
Create New ASP.NET MVC 3 Web Application
Select Internet Application—>Razor View Engine ->HTML 5 markup->OK
A typical MVC application contains following folder structure…
- The App_Data folder is used for storing application data.
- The Content folder is used for static files like style sheets(css files) , icons and images.Visual Studio automatically adds a theme folder to the content folder.The themes folder is filled with JQuery styles and pictures.Visual Studio also adds standard style sheet file to the project. Site.css
The Controllers Folder
- The Controllers folder contains the controller classes responsible for handling user input and responses.
- MVC requires the name of all controller files to end with “Controller”.
- Visual Studio has created a HomeController (For Home and About Page) and AccountController(For Login Page)
The Models Folder
- The Models Folder contains the classes that represent the application models.
- Models hold and manipulate the Application Data.
- Visual Studio has automatically created AccountModels(For Login Page).
The Views Folder
- The Views folder stores the HTML files related to the display of the application(the User Interfaces).
- The Views folder contains one folder for each controller.
- Visual Studio has created an Account Folder , a Home Folder and a Shared Folder inside the Views Folder.
- The Account folder contains pages for registering and logging in to user Accounts.
With this article, you got the basic idea behind using ASP .NET MVC architecture.In my next article we will discuss how to make simple application in MVC .