Basics for ASP.NET MVC

MVC Basics:-

The ASP.NET MVC is web application framework that implements the model–view–controller (MVC) pattern.
The Model-View-Controller (MVC) architectural pattern separates an application into three main components:-
M – Model encapsulates the core application data (provides data to the View)
V – View obtain data from model and present it to user (Part of application that display data/ responsible for         the look and feel)
C –Controller is the part of application that handles the user interaction, typically controller read data from           view, Control user input & sends input data to model. (Take the end user request and load the appropriate     Model and View)

Benefits of using MVC:-
  • When we talk about benefits of using MVC first thing come in mind is, its lightweight.
  • Using MVC Clean Separation concerns in application is achieved, well defined and architected.
  • It makes it easier to manage complexity by dividing an application into the model, the view, and the controller.
  •  Full control over the behavior of an application as it does not use view state or server-based forms.
  • Full control over URL.
  • It provides better support for test-driven development (TDD).
To create MVC application, if you are using VS12 or VS13 then Go to New Project>>Web>>ASP.NET MVC 4/3 Web Application>>OK>>Internet Application>>OK
Refer Below screen for more details,

Folder structure in MVC:- 
If you are new to MVC then you might find folder structure in MVC quite difficult, as here no .aspx pages, no code behind file is available to code. Below screen display the basic structure of MVC,

  1. App_Data:- Contain the application data, e.g. compact SQL database   if you are using any.
  2. App_Start:- Contains the configuration file for the application.
  3. Content: Contains the static files like style sheet, icons, images.
  4.  Controllers: - Contains controller files, Name of all controller files must end with controller, they are nothing but class files.
  5. Images:- Contains Images
  6. Mode: - Contains Model or object class files.
  7. Scripts: - Contains the JavaScript files.
  8. Views: - Contains view files may have extension .cshtml or .vbhtml depending                   on language you are using. For each controller there is one folder is                   associated and that contains view of that controller. Shared folder                     contains Shared view pages across the application i. e. Layout/master.
  9. Config files at end.

      Flow in MVC (in short):-
When a user enters a URL into the browser, the MVC application uses routing rules that are defined in the Global.asax file to parse the URL and to determine the path of the controller. The controller then determines the appropriate action method to handle the request and return the view, in view first c#/vb code is first executed on server site and then view renders HTML to browser.

Comments