Understanding ASP.NET Core MVC Folder Structure
.NET MVC Web Development

Understanding ASP.NET Core MVC Folder Structure

Mishel Shaji
Mishel Shaji

When you scaffold a new ASP.NET Core Model-View-Controller (MVC) project—whether through the .NET CLI or Visual Studio—the framework generates a standardized set of folders and files. For a beginner, looking at this file tree for the first time can feel overwhelming.

For further reading:

Understanding the MVC Architecture Pattern
If you are stepping into the world of web development, MVC (Model-View-Controller) is one of the most fundamental design patterns you will encounter. It is the architectural spine behind many massive web frameworks.

However, this structure isn't random. It follows the Convention over Configuration principle. This means .NET expects certain files to be in specific places so that the framework can connect your code automatically without you having to write complex configuration paths.

Let’s break down the default folder structure layout of a .NET 10 MVC project piece by piece.

The Bird's-Eye View

Here is what a freshly generated MVC project looks like in your file explorer:

MyBlogApp/
│
├── Controllers/
│   └── HomeController.cs
│
├── Models/
│   └── ErrorViewModel.cs
│
├── Views/
│   ├── Home/
│   │   ├── Index.cshtml
│   │   └── Privacy.cshtml
│   ├── Shared/
│   │   ├── _Layout.cshtml
│   │   └── Error.cshtml
│   ├── _ViewImports.cshtml
│   └── _ViewStart.cshtml
│
├── wwwroot/
│   ├── css/
│   ├── js/
│   └── lib/
│
├── appsettings.json
├── MyBlogApp.csproj
└── Program.sh

1. The Core MVC Folders (The Big Three)

The heart of the pattern is divided into three distinct directories. Each has a strict, single responsibility.

📁 Controllers/

The Controller acts as the "brain" or the traffic cop of your application. When a user visits a URL (like mysite.com/Home), the request lands here first.

  • What's inside: Regular C# classes that end with the suffix Controller (e.g., HomeController.cs) and inherit from Microsoft.AspNetCore.Mvc.Controller.
  • How it works: Methods inside these classes (called Action Methods) process user requests, talk to the database if needed, and decide which View to display back to the user.

📁 Models/

The Model represents the data structures, shapes, or business logic of your application.

  • What's inside: Pure C# classes or objects (often called POCOs - Plain Old CLR Objects). For example, if you are building an e-commerce site, you would create a Product.cs file here containing properties like Id, Name, and Price.

📁 Views/

The View is the user interface—what the user actually sees on their screen.

  • What's inside: Subfolders that strictly match your Controller names, housing files with a .cshtml extension.
  • The Magic Relationship: If you have a HomeController, you must have a folder inside Views named Home. Inside that Home folder, your .cshtml files blend standard HTML with C# code using a special syntax engine called Razor.

2. The Global UI Folders (Inside Views)

Within the Views/ directory, you will notice a few special files and folders that handle your website's global layout:

  • 📁 Views/Shared/: Contains UI elements shared across the entire website.
    • _Layout.cshtml: This is your website’s master template layout block. It contains the global <html>, <head>, <body>, navigation bars, and footers so you don't have to rewrite them on every single page.
  • _ViewStart.cshtml: A tiny initialization file that automatically sets the default layout template for all pages. It tells the system, "Hey, unless stated otherwise, use _Layout.cshtml as the frame for every view."
  • _ViewImports.cshtml: Houses global configuration namespaces. If you want to use a specific C# library across all your UI files without writing @using MyLibrary at the top of every single file, you declare it here once.

3. The Public Core Asset Folder: wwwroot/

The wwwroot/ folder is the only folder in your entire project that the outside web browser can access directly. If a file is not placed inside wwwroot/, it cannot be loaded by an HTML image tag or a script link.

  • What's inside: Static assets like custom CSS stylesheets, JavaScript files, images (.png, .jpg), and external client-side packages like Bootstrap or jQuery (stored inside the lib/ subfolder).

4. Application Configuration Files

At the root level of your project directory sit the files that control how your application compiles, starts, and behaves across different servers.

📄 Program.cs

This is the absolute entry point of your application. When you run dotnet run, the system executes this file first. It sets up your web server (Kestrel), registers dependencies (like database connections or authentication rules), and configures the HTTP request routing middleware pipeline.

📄 appsettings.json

The centralized settings registry configuration file.

  • What's inside: Key-value pairs stored in JSON format containing data you don't want hardcoded inside your actual C# code files. This includes database connection strings, logging level controls, or third-party API secret tokens.

📄 ProjectName.csproj

The primary project manifest description file. Written in XML syntax, it tracks the target .NET runtime version (.NET 10), project deployment styles, and the collection list of third-party external NuGet packages installed in the application.

Summary

Folder/File Purpose Target Audience Accessible via Web URL?
Controllers/ Handles requests, coordinates logic. C# Code Compiler No
Models/ Defines data structures & entities. C# Code Compiler No
Views/ Generates the HTML user interface. UI Layout/Browser No (indirectly rendered)
wwwroot/ Hosts static assets (images, CSS, JS). Browser Engine Yes (Direct access)
Program.cs App startup and routing engine pipeline. .NET Runtime No

Practice Questions

1. A developer places an image file named logo.png inside the Controllers/ folder and tries to load it via an HTML image tag <img src="/Controllers/logo.png" />. Will the image display in the browser?

  • Answer: No. Only files stored inside the public root directory wwwroot/ are accessible to external web browser queries. The server blocks direct URL requests to any other internal source directories for security purposes.

2. If you create a brand new controller class named ProductController.cs, what folder structural update must you perform inside the Views/ directory?

  • Answer: You must create a new folder inside the Views/ directory explicitly named Product to hold any corresponding .cshtml layout files that the action methods inside your ProductController will call to render.

3. What is the explicit purpose of the appsettings.json file in a .NET project structure?

  • Answer: It stores configuration keys, environment behaviors, security values, and database connection profiles safely outside the main compiled C# logic code, allowing them to be easily adjusted without re-compiling the application binaries.

4. True or False: The _Layout.cshtml file inside the Views/Shared/ folder must be copied and pasted into every controller view folder manually to keep the application header consistent.

  • Answer: False. Thanks to the global execution rule located inside _ViewStart.cshtml, the framework automatically uses _Layout.cshtml as the overarching UI container shell for all pages implicitly.