ASP.NET MVC Folder and File Structure
In this article, I am going to discuss the auto-generated ASP.NET MVC Folder and File Structure when we create a new ASP.NET MVC application. Please read our previous article before proceeding to this article where we discussed how to create ASP.NET MVC 5 application step by step from scratch.
Nowadays, the ASP.NET MVC framework becomes more popular among the developers because of the separation of concerns (codes) and folder structure. As a developer, it is very important for you to understand the need and use of each folder and file of an ASP.NET MVC application.
When we create an ASP.NET MVC 5 application, the Visual Studio by default creates the following folders and files for our application.
Let us discuss the use and need of each Folder and File of an MVC application in details one by one.
The App_Data folder of an MVC application is used to contain the application related data files like .mdf files, LocalDB, and XML files etc. The most important point that you need to remember is the IIS is never going to serve files from this App_Data folder. In our example, this folder is empty as we don’t have any data files. In our upcoming articles, we will discuss how to store application-related data files in App_Data Folder.
The App_Start folder of an MVC application is used to contain the class files which are needed to be executed at the time of application starts. The classes like BundleConfig, FilterConfig, RouteConfig, IdentityConfig, etc are stored within this folder. So in the simple word we can say that configuration related class files are stored here. We will discuss the use of each of these class files in detail in our upcoming articles.
The Content Folder of an MVC application is used to store the static files such as the image files, CSS files, and icons files. When we create an MVC 5 application, by default the bootstrap.css, Site.css, and bootstrap.min.css files are included by the visual studio as shown in the image below.
The Controllers Folder in MVC application is used to contains all the controllers of your application. The Controller is basically a class which is inherited from the base Controller class. The name of the Controller should end with the word “Controller”. It is this class which actually handles the user’s request and returns a response. In our upcoming articles, we will discuss the controllers in details.
The Fonts folder of an MVC application contains the custom font files that are required for the application.
The Models folder of an MVC application is used to store the class files which are used to store the domain data as well as business logic to manage the data. In our example, the Models folder is empty as we have not created any models for our application. In our upcoming articles, we will discuss Models in detail.
The Views Folder of an MVC application is used to contains the “.cshtml” files for the application. In MVC, the .cshtml file is a file where we need to write the HTML code along with the C# code.
The Views folder in MVC application includes separate folders for each and every controller for your application. For example, all the .cshtml files of the HomeController will be in the View => Home folder.
We also have the Shared folder under Views folder. The Shared Folder in MVC is used to contains all the views which are needed to be shared by different controllers e.g. error files, layout files, etc.
Now, let us discuss the configuration files which is created by the framework by default:
The Global.asax file in an MVC application allows us to write code which we want to run at the application level, such as Application_BeginRequest, application_error, application_start, session_start, session_end, etc. In our upcoming articles, we will discuss the use of these application level events in detail.
The Packages.config file in MVC application is managed by the NuGet which will keep track of what packages and versions have installed within your application.
The Web.config file of an MVC application is one of the most useful and important files which contains the application level configurations.
Here in this article, we discussed the ASP.NET MVC Folder and File structure. Once you understand the need and use of each folder and file of an MVC application, then it is easy for you to find, store and organize project related files. In the next article, we are going to discuss the Controllers in ASP.NET MVC application.
In this article, I try to explain the need and use of ASP.NET MVC Folder and File structure which are auto-generated by the Visual Studio. I hope this article will help you with your need. I would like to have your feedback. Please post your feedback, question, or comments about this article.