In this article, we will create a simple example of an ASP.NET MVC project. To create ASP NET MVC Application, we will have to install the latest Visual Studio installer. In this tutorial, we’ll help you on how you can start new ASP.NET Web Application Projects, and hopefully, later on, we’ll help you to create your first Web Application.
What is ASP.NET MVC?
What is MVC?
MVC is an architectural pattern known as Model-View-Controller. This architecture separates your application into three logical components.
- Model – The Model is the properties of the data inside your application. Model is created using C# classes.
- View – The View is the main user interface of an application. This part is where all the data will be displayed.
- Controller – The controller handles the user request. The user request using the view and send an HTTP request to the controller to process the request.
Before we start, Please make sure to have installed the latest Visual Studio. Link
Create ASP.NET MVC Project
Step 1. Open your Visual Studio then create a new project.
Step 2. Another window will open. Search for ASP.NET Web Application then click on the next button to proceed.
Step 3. Configure your project. Please assign a name for your project. In my case, I named it MVCWebApp. Once you have set all the configuration settings, click on the create button.
Step 4. Now, we have two options to start a project we can use the MVC template, or we can start from an empty project. We will use the empty MVC template. Click on the create button.
Step 5. Wait for Visual Studio to create your projects. A new project solution will be open once done. This is how an empty MVC project solution will look like. See the image below.
Now, when you run the project by pressing F5. You will have the error from the image below since we started a project with an empty solution. We need to create the controller manually.
Step 6. Create a controller by right-clicking on the controller folder then select Add » Controller.
Step 7. A popup window will appear, select MVC 5 controller then click the Add button.
Step 8. Name your controller. Then press Add.
This will create a new controller with a default Index method.
Step 9. Now, all we need to do is to create a View. We will create a view for this index method. To do that, right-click on the Index method from HomeController.
Step 10. Add window will popup. Click add to proceed.
This action will create an Index.cshtml file under Views » Home folder. Adding a view also creates a file named _Layout.cshtml, this is the base layout of your application. This file is where your navigation menu is located. See the image below.
So, finally you can rerun your project to see if your ASP.NET MVC Application is now working.
To modify Application Name and adding of menu. Use the _Layout.cshtml file under Shared folder.
This article is a guide for beginners. We have demonstrated a step by step process on how we can create ASP NET MVC Application using an Empty MVC Project. If you want to familiarize yourself with the structure of a .NET MVC check out this article. Hopefully, you can use this article for your reference for your future projects. Happy coding!