In this article, I will discuss the auto-generated files and folder structure that are created when setting up a new ASP.NET MVC project. Before proceeding, I recommend checking out our previous article, where we covered the step-by-step process of creating an ASP.NET MVC 5 application from scratch.
Nowadays, the ASP.NET MVC framework is gaining popularity among developers due to its separation of concerns (better code organization) and well-structured folder hierarchy. As a developer, understanding the purpose and usage of each file and folder in an ASP.NET MVC application is crucial. When we create an ASP.NET MVC 5 application, Visual Studio automatically generates the following files and folders by default.
Now, let's explore the purpose and functionality of each file and folder in detail, one by one.
App_Data:Now, let's explore the purpose and functionality of each file and folder in detail, one by one.
The App_Start folder in an ASP.NET MVC application holds configuration-related class files that run when the application starts. It contains classes like BundleConfig, FilterConfig, RouteConfig, IdentityConfig, and others. We will cover the purpose and functionality of each of these class files in detail in our upcoming articles.
The Content folder in an ASP.NET MVC application stores static files, such as images, CSS files, icon files, and more. When you create a new ASP.NET MVC 5 application, Visual Studio automatically adds files like:
The Controllers folder in an ASP.NET MVC application contains all the controllers used in the application. Controllers are classes that derive from the base Controller class. The name of each controller must end with the word "Controller". These classes are responsible for handling user requests, such as incoming HTTP requests, and generating responses. In our upcoming articles, we will explore controllers in greater detail.
The Fonts folder in an ASP.NET MVC application stores custom font files that are required for the application's design and styling.
The Models folder in an ASP.NET MVC application contains class files that store domain data (also known as business data) as well as the business logic to manage that data. In our example, the Models folder is empty because we haven’t created any models for the application yet. In our upcoming articles, we will discuss Models in detail.
The Scripts folder in an ASP.NET MVC application holds all the JavaScript files required for the application. When you create an ASP.NET MVC 5 application, Visual Studio automatically includes essential JavaScript files for jQuery and Bootstrap by default. If you need to create custom JavaScript files, they should be placed in this folder or within a subfolder inside it. Although this is not mandatory, it is considered good programming practice as it helps in organizing and easily locating JavaScript files later.
The Views folder in an ASP.NET MVC application contains all the .cshtml files for your application. In MVC, a .cshtml file is where you write both HTML and C# code.
The Views folder also has separate subfolders for each controller in your application. For instance, all the .cshtml files for the HomeController will be placed in the Views => Home folder.
Moreover, there is a Shared folder under the Views folder. The Shared folder includes views that are shared across multiple controllers, such as error pages, layout files, and other common views.
Now, let's discuss the configuration files that are automatically created by the framework by default:
The Global.asax file in an ASP.NET MVC application allows you to write code that runs at the application level (or global level). This includes events such as Application_BeginRequest, Application_Error, Application_Start, Session_Start, Session_End, and more. In our upcoming articles, we will discuss the use of these application-level events in detail.
The Packages.config file in an ASP.NET MVC application is managed by the NuGet Package Manager. It keeps a record of the packages and their versions that have been installed in your application.
The Web.config file in an ASP.NET MVC application is one of the most essential and valuable files. It holds application-level configurations, including connection strings, global variables, and various other settings.
In this article, we explored the ASP.NET MVC file and folder structure. Once you comprehend the purpose and function of each folder and file in an MVC application, it becomes much easier to locate, store, and organize project-related files effectively.
In the next article, we will explore Controllers in ASP.NET MVC applications. In this article, I have explained the purpose and usage of the ASP.NET MVC file and folder structure that is automatically generated by Visual Studio. I hope this article has been valuable and informative for you.