Reader Level:
ARTICLE

Folder Structure of ASP.Net MVC Project

Posted by Sandeep Singh Shekhawat Articles | ASP.NET MVC June 10, 2013
This article explains the default folder structure of ASP.NET MVC project and describes purpose of each folder.
  • 0
  • 0
  • 15809

This article explains the default folder structure of an ASP.NET MVC project and describes the purpose of each folder. When we create a MVC 2 project using Visual Studio, two projects are created and one of them is a Web Application project and the other is a Test project for the Web Application project.

Folder-Structure-of-ASP.NET-MVC-Project1.jpg
In the picture above we can see six main folders so let's see each one by one.

1. Content

This folder contains Cascading Style Sheet files and images. This folder is used for static and publically servable files (*.css).

Folder-Structure-of-ASP.NET-MVC-Project2.jpg

2. Controllers

This folder contains C# classes files that are controller classes. Controllers are responsible for handling end user interaction, manipulating the model and choosing a view to display the UI. Each controller class inherits a Controller class or IController interface. Each controller class name has "Controller" as a suffix on the class name.

Folder-Structure-of-ASP.NET-MVC-Project3.jpg

It is just a suggestion. It makes no difference whether we put controllers directly into this folder, into a subfolder of it, or anywhere else in the entire project or into another referenced project or assembly. Because we know that these are classes and all of them are compiled into the same assembly.
 
3. Models

This folder contains classes that define objects and the logic for interacting with the database or data items. The Model is used by both the View and the Controller to view and edit.

Folder-Structure-of-ASP.NET-MVC-Project4.jpg

It is better to put model classes into a separate class library project.
 
4. Scripts

The Scripts folder is the recommended folder to store Java Script files in our MVC web application. We put static and publicly accessible files for jQuery and Java Script validation files (*.js) in this folder.

Folder-Structure-of-ASP.NET-MVC-Project5.jpg 

5. Views

This folder holds views (*.aspx, *.ascx and *.cshtml files). It is where files for displaying the application's user interface are placed. The Views folder contains a subfolder for each Controller and Views for the Controller action results. The View's sub folder is named with the controller-name-prefix and View is named with the controller action.

Folder-Structure-of-ASP.NET-MVC-Project6.jpg

The Views folder contains a Web.config file. It is not our application's main Web.config file. It contains a directive instructing the web server not to serve any *.aspx files under /Views because they should be rendered by a controller, not invoked directly like Web Forms (*.aspx files). It also contains the configuration that is needed to make the standard ASP.NET ASPX pages compiler work properly with ASP.NET MVC view syntax.  
 
6. Views\Shared

The Shared folder is a subfolder of the Views folder. It used for multiple views. It holds global Master Pages, Error Pages and User Controls used by multiple controllers. This folder is not associated with any particular Controller.

Folder-Structure-of-ASP.NET-MVC-Project7.jpg

 MVC Web Applications have some other folders that are the same in Web Form Web Applications.

  1. App_Data: It is used as data storage for the MVC Web Application. It is a natural storage point for file-based data stores (*.mdf, *.mdb and *.xml) because IIS won't serve any files from it but we can access them in our application.
  2. Bin: It holds the compiled .NET assembly for our MVC web application and any other assemblies it references. IIS expects to determine the DLLs in it. During compilation VS copies any referenced DLLs (excepts those from the system-wide global assembly cache) to it. IIS won't serve its content to the public.

COMMENT USING

Trending up