Table of contents
1.
Introduction
2.
ASP.NET MVC Folder Structure
2.1.
App_Start
2.2.
App_Data
2.3.
Content
2.4.
Controllers
2.5.
Models
2.6.
Scripts
2.7.
Views
2.8.
Global.asax 
3.
FAQs
4.
Key Takeaways
Last Updated: Mar 27, 2024

ASP.NET MVC Project Structure

Author Aryan Raj
2 upvotes
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

ASP.NET is a high-performance, cross-platform, open-source framework for building modern, cloud-based, Internet-connected web applications. It is a rich framework for building web applications and APIs using the Model-View-Controller (MVC) design pattern. 

While creating an ASP.NET MVC project, we should be aware of the project folder structure. So, Let’s dive into the topic and have a brief introduction about it.

ASP.NET MVC Folder Structure

While creating a project in ASP.NET MVC Visual Studio(VS) Code creates the following folder structure of the MVC application by default.

App_Start

The App_Start folder contains class files executed when the application starts. Generally, all the configuration files like, e.g., Router Configuration, Filter Configuration, Bundle Configuration.

MVC (V) includes FilterConfig.cs, BundleConfig.cs, and RouteConfig.cs by default. 

 

App_Data

The App_Data folder contains all data required to read & write into the application, data files like LocalDB, XML files, .mdf files, and other data-related files. IIS will never serve files from the App_Data folder.

Content

The Content folder contains static files like Cascading Style Sheet files, images, and icons files. By default, the MVC (V) application includes bootstrap.css, bootstrap.min.css, and Site.css.This Content folder is used for static and publically servable files (*.css). 

 

Controllers

The Controllers folder contains C# class files for the controllers. Controllers are responsible for manipulating the model, handling end-user interaction, and choosing a view to display the UI. 

A Controller handles users' requests and returns a response. Each controller class name has "Controller" as a suffix on the class name.

Models

The Models folder contains classes that define objects and the logic for interacting with the database or data items. It includes public properties, which will be used by the application to hold and manipulate application data.

The Model is used by both the Controller and the View to edit and view. It is always better to put model classes into a separate class library project.

Scripts

The Scripts folder contains JavaScript and VBScript files for our MVC web application. By default, MVC (V) includes javascript files for bootstrap, jquery 1.10, and modernizer. We put static and publicly accessible files for jQuery and JavaScript validation files (*.js) in this folder.

Views

The Views folder holds HTML files for the application. The files for displaying the application's user interface are placed here. Generally, a view file is a .cshtml file where you write C# and HTML or VB.NET code.

This folder includes a separate folder for each controller. For example, all the .cshtml files, which will be rendered by HomeController, will be in the View > Home folder.

The View's subfolder is named with the controller-name-prefix, and View is named with the controller action. 

 

Global.asax 

When your application has deployed the server, global.asax file is the main file. When the first request comes to the server, it reaches Global.asax first. Global.asax file allows us to write code that runs in response to application_start, application-level events, application_error, such as Application_BeginRequest, session_start, session_end, etc.

 

FAQs

  1. What is bundling and minification in MVC?
    Bundling and minification in MVC are two separate techniques to reduce the load time. The bundling minimizes the number of requests to the Server, while the minification minimizes the size of the requested assets.
     
  2. When to Use ViewResult?
    The ViewResult property can be used if you know that your action method will return a page. The return-type of this method can be the more general ActionResult class. Nevertheless, your action method may behave differently, such as rendering a view or performing a redirection. 
     
  3. Explain routing and its three segments?
    Routing helps decide a URL structure and map the URL with the controller. The three important segments for routing are as follows:
    ControllerName
    ActionMethodName
    Parameter
     
  4. Can we have multiple _ViewStart in MVC?
    Yes, We can create multiple _ViewStart.cshtml pages. The file execution depends on the file's location within the folder hierarchy and the view being rendered. The MVC Runtime will first execute the code of the _ViewStart.

Key Takeaways

This blog has discussed  ASP.Net MVC project folder structures like App_Start, App_Data, Content, Controllers, Models, Scripts, Views, and Global.asax, etc.

Apart from this, you can also expand your knowledge by referring to these articles on Features Of ASP Net and ASP Full Form.

You can also consider our Online Coding Courses such as the DSA in PythonC++ DSA CourseDSA in Java Course to give your career an edge over others.

Happy Learning, Ninja!

Live masterclass