In this tutorial, we will make a simple ASP.NET MVC web application using empty project. This application will show a statement “Hello world..! Congratulation you have created your first ASP.NET MVC Web Application” using visual studio 2015. After this tutorial, you will be able to know how to create an asp.net mvc web application project, how to run a project on visual studio, and will also know that the purpose of every folder and file in empty project.
If you don’t know about “What is ASP.NET MVC” then just see the previous tutorial Introduction.
Create First ASP.NET MVC Web Application
Now follow these steps.
Step # 1: Open the Visual Studio.
Step # 2: Click on File, then New and choose Project.
File -> New -> Project
Step # 3: From the left pane, select templates, then choose Visual C# then choose the web (Templates -> Visual C# -> Web). Then choose ASP.NET Web Application in the middle pane. Then Enter the Project name (E.g. FisrtMVCApp) in the name field.
Note:- Name should be without spaces.
Step # 4: Select the Empty Option and then check the MVC Checkbox under the ‘Add Folders and Core references for’. Then simply click on the Ok button.
Now, this will create a simple project with a number of files and folders in the solution explorer window.
Now we discuss that folders and files.
It will contain all the properties of your Project.
All are the project references or assemblies are in this folder.
This folder contains the database of your project.
App_Start folder has been introduced in asp.net MVC4. This folder contains all the startup files of your application
This folder contains all the controller of your Application(Logic of your application).
This folder contains all the models of your application (Data of your application).
This folder contains the views of your application.
This file contains code for responding to the Application level. It resides in the root directory of an ASP.NET based Application.
This folder contains all the configuration files of your project that is applicable for entire MVC application.
Step # 5: Just press fn+f5 to run your application (or from Debug -> Start Debugging). But your application will get an error 404 Not Found. It is because your application does not contain anything to run in the browser.
Step # 6: To get rid of this 404 Not Found error, we need to add a controller in controllers folder.
Add Controller: Right click on the controller folder in the solution explorer and then select Add and then choose Controller (Right click on controller folder -> Add -> Controller). It will show the add Scaffold dialog.
Step # 7: Choose the MVC 5 Controller – empty option and click Add button then it will show an add controller dialog.
Note:- Controller name should end with Controller otherwise it will wrong.
Then you will see your HomeController.cs Page.
Step # 10: Now the last step, just Run your application from Debug -> Start Debugging (or fn+f5).
Congratulation you have created your first ASP.NET MVC Application.