ASP.NET Core MVC WebApplication
Based on Project Structure
Hi guys! Welcome to my second blog.
I’ll discuss a brief introduction to ASP.NET Core MVC and project structure of an ASP.NET Core MVC web application.
ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. It is a rich framework for building web applications and APIs using the Model-View-Controller (MVC) design pattern.
MVC pattern?
The Model-View-Controller (MVC) architectural pattern separates an application into three main groups of components: Models, Views, and Controllers. This pattern helps to achieve separation of concerns.
The Model in an MVC application represents the state of the application and any business logic or operations that should be performed by it.
Views are responsible for presenting content through the user interface. There should be minimal logic within views, and any logic in them should relate to presenting content.
Controllers are the components that handle user interaction, work with the model, and ultimately select a view to render. In the MVC pattern, the controller is the initial entry point and is responsible for selecting which model types to work with and which view to render.
The following diagram shows the three main components and which ones reference the others:
Project Structure?
First, we will create a project in Visual Studio. Open File -> New -> Project… and select ASP.NET Core Web Application in the following window:
Now give your project a name and then press OK.
In the next window, select Web Application (Model-View-Controller) and be sure that .NET Core and ASP.NET Core are selected as shown below:
After pressing OK, the starter project is created as below:
In ASP.NET Core, Dependencies is the place where the necessary for the application are stored.
Under the Properties menu, you can see a file called launchSettings.json which describes how a project can be launched. It describes the command to run, whether the browser should be opened, which environment variables should be set, and so on.
Static content is hosted in the wwwroot folder. The content such as CSS, Javascript files and Bootstrap, jquery libraries need to be included here.
Controller, Models and Views folders are automatically created as we chose Web Application (Model-View-Controller) in the above screenshot. These support MVC pattern and we will add new files to those folders.
appsettings.json is used to store information such as connection strings or application specific settings and these are stored in the JSON format as the file extension suggests.
At the bottom there are two classes: Program.cs and Startup.cs.
Program.cs is the main entry point for the application. It then goes to the Startup.cs class to finalize the configuration of the application.
Startup.cs includes Configure and ConfigureServices methods.
Then,Index
method in the HomeController.cs
returns the view Index.cshtml
which can be found under /Views/Home/ .
Let’s run the project to see how it comes at first. I will use IIS Express as the web server and Firebox as the web browser to run the application:
We can get the Welcome page as below:
Hopefully, you had a general idea about the structure of an ASP.NET Core MVC Web Application starter project.
Thanks for reading!!!
References
https://docs.microsoft.com/en-gb/aspnet/core/mvc/overview?view=aspnetcore-2.2
https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-2.2
https://docs.microsoft.com/tr-tr/aspnet/core/fundamentals/startup?view=aspnetcore-2.2
https://www.tutorialsteacher.com/core/aspnet-core-startup
https://blog.jetbrains.com/dotnet/2018/11/08/using-net-core-launchsettings-json-rundebug-apps-rider/