Web Programming ASP.NET MVC .NET Framework - Lesson 1 - Introducing ASP.NET MVC
Create your first ASP.NET MVC (.NET framework) project
Name the project HelloWorld
Use the Visual Studio 2022 IDE
Click "Create a new project" to create a new project
Find the template: ASP.NET Web Application (.NET Framework). Click Next
Name the project "HelloWorld-codingwiththinh.blogspot.com" (do not use special characters)
Select the save location as the folder "My ASP.NET" (do not use special characters)
Select Framework as .NET Framework 4.8
Click Create
Select template as Empty
Check the MVC checkbox to create a project according to the MVC model (Model - View - Controller)
Click Create
Structure of ASP.NET MVC project:
1. Main project directories:
Includes 3 main folders: Models, Views, Controllers
- Controllers: Contains controllers, which handle requests from users, interact with the Model, and return results in the form of views or JSON data. Controller is the place that receives and processes requests from users. It interacts with the model to get data and then passes this data to the view.
- Models: Contains Model classes, including classes containing data of the Web application and classes related to the business of the Web application (also known as the Logic part of the application).
- Views: Contains Views. View is where the user interface is defined. It uses HTML code and Razor code to display data.
2. Other folders:
Includes 2 folders: App_Data, App_Start
- App_Data: Folder contains data files such as databases.
- App_Start: Contains startup configuration files such as RouteConfig.cs, FilterConfig, BundleConfig, and AuthConfig.
Additionally, you can create a new folder: Fonts (containing font files) Images (containing image files)...
3. Main files of the project:
In the ASP.NET MVC .NET Framework project, there are 3 main files: Global.asax, Web.config, packages.config
- Global.asax: Define web app events such as Application_Start, Application_End, Application_Error...
- Web.config: The main configuration file of the application (in a project there can be many config files, the config file at the same level as the main folder of the project is called the main configuration file). Configure the database connection (mainly pay attention to the database connection), configure HTTP modules, and configure handlers.
- packages.config: List NuGet packages that the web app uses. Except for managing Nuget Package packages with the Package Manager Console and managing with the interface, you can manage those packages through the packages.config file, such as adding or deleting packages and changing the version of the package. After editing the packages.config file, you need to run the following command in Package Manager Consol: Update-Package -Reinstall. Or right-click on the solution and select "Restore NuGet Packages"
Regarding the References section (project structure), managing libraries and packages (it lists the libraries and packages used in the project) (Usually, this section is not modified.)