In this post, we will see what is MVC and how we can use it in our ASP.NET web applications.
MVC – Model, View, Controller
MVC pattern is one of the most popular design patterns these days and almost all the technologies whether Java, Rails, PHP have MVC frameworks to work with.
MVC design pattern makes developing web applications much more easy and standardized. It provides lot of pre-defined functionalities that we can use in our application.
MVC patten encourages strict isolation between the individual parts of the application.
MVC design have three components:
Model represents the business logic of the application. Models are responsible for representing entities of the project. They also use to save or retrieve the data from database.
Controllers contains methods that represents URLs in the application. A controller acts as an intermediate between view and model.
Advantages of MVC
- It provides a clean separation of components.
- It is easier to test each component separately.
- It facilitates de-coupling of application layers with the help of dependency injection.
- It is easy to scale the application.
- It is easy to customize views by using different templates.
Directory Structure of ASP.NET MVC Project
Here is the directory structure of a typical ASP.NET MVC project:
This directory organizes all the components of the application. We will be writing most of our code under this directory.
This directory contains the bundle, rails and rake executables that are needed to execute various rails commands
This directory contains images and CSS files.
This directory contains controller class files.
This directory contains fonts we can use in our web application.
All your application logs will be stored here.
This directory contains folders with the name of controllers. Each folder contains view files corresponding to actions in the controller.
This file contains methods corresponding to events in your web application like application start, session created etc.
This file is managed by the NuGet package manager. It is used to track installed packages with their respective versions.
This file contains class that helps in adding and configuring various middle wares in the application like Autofac for dependency injection.
This is the main settings and configuration file for an ASP.NET web application. It is an XML document that resides in the root directory of the application and contains data about how the web application will act.
There are other files/directories in the project that are generated dynamically as we add more stuff.