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.
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).
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.
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.
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.
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.
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.
MVC Web Applications have some other folders that are the same in Web Form Web Applications.
- 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.
- 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.