MVC Basics for Beginners

MVC Basics

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
  • ModelModel holds application data , data access logic.
  • ViewMarkup and content that is returned to the browser
  • ControllerFires 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. 

    mvc

Wait..Wait..Why MVC????

  • 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

mvc1

Select Internet Application—>Razor View Engine ->HTML 5 markup->OK

mvc2

A typical MVC application contains following folder structure…

mvc3

mvc4

  • 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

mvc5

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)

mvc6

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). 

mvc7

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.

mvc12

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 .

 

Leave a Reply

Your email address will not be published. Required fields are marked *