ASP.NET Core MVC Web Application Project Structure

All ASP.NET Core web templates have a similar structure. For ASP.NET Core 3.1 web applications, it is best practice to have the following structure for your projects:

Program.cs is the main entry point of the application, and it runs the default web server used by APIs.

Startup.cs defines and configures our application pipeline and services.

Properties/launchSettings.json file represents the settings for our project.

appsettings.json contains the settings based on our environment.

A Controllers folder, containing all of the controllers of your application.

A Services folder, containing all the services of your application (for example, external communication services).

A Views folder, containing all the views of your application. This folder should contain a single Shared subfolder as well as one folder per controller.

A _ViewImports.cshtml file, to define some namespaces to be available in all views.

A _ViewStart.cshtml file, to define some code to be executed at the start of each view rendering (for example, setting the layout page for all views).

A _Layout.cshtml file, to define a common layout for all of your views.

Create the project structure

Step 1 : Start Visual Studio 2019, open the LearningAspNetCore Core 3.1 project you have created, create three new folders called Controllers, Services, and Views, and then create a subfolder called Shared in the Views folder:

Step 2 : Create a new view page called _ViewImports.cshtml in the Views folder:

@using LearningAspNetCore
@addTagHelper*, Microsoft.AspNetCore.Mvc.TagHelpers

Step 3 : Create a new view page called _ViewStart.cshtml in the Views folder:

@{ Layout = "~/Views/Shared/_Layout.cshtml"; }

Step 4 : Right-click on the Views/Shared folder, select Add > New Item, enter Layout in the search box, select Razor Layout, and then click on Add:

Add Comment