ASP.NET MVC Folder and File Structure

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.

ASP.NET MVC Folder and File structure

Let us discuss the use and need of each Folder and File of an MVC application in details one by one.

App_Data:

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.

App_Start:

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.

App_Start folder of MVC application

Content:

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.

Content folder in MVC Application

Controllers:

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.

Controllers folder in MVC application

Fonts:

The Fonts folder of an MVC application contains the custom font files that are required for the application.

Fonts folder of an MVC application

Models:

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.

Scripts:

The Scripts Folder of an MVC application is used to contains all the JavaScript files that are required for the application. When we create an MVC 5 application, by default the necessary javascript files for jquery and bootstrap are included. If you want to create any custom javascript files then it should be created within this folder or any subfolder of this folder. This is not mandatory but it is a good programming practice as in later time you can easily find out the javascript files. 

Scripts Folder of an MVC application

Views:

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.

Views Folder of an MVC application

Now, let  us discuss the configuration files which is created by the framework by default:

Global.asax:

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.

Packages.config:

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.

Web.config:

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.

SUMMARY

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.

Leave a Reply

Your email address will not be published. Required fields are marked *