In this part of tutorial you will learn about adding controllers and views in MVC application.
In MVC, Controllers and Views are the basic blocks- One is used to show UI to users and to take request and another to controll these request and send response to end users. Till now you have learned creating new project and adding references into it. You are also aware aout the basic structure of MVC. Now let's move to next step and try to add controllers and views to the project.
Follow below steps to add Controller to application.
Step 1: Right click on Controllers folder and click Add > Controller.
Step 2: A new popup opens. Select MVC 5 Controller - Empty and click Add.
Step 3: Add Controller popup will show up. Name your controller.
A newly added controller will look like this.
Follow below steps to add Views.
Step 4: Right click on Index action method and click Add View.
You can also add view by right clickig Views folder. Steps will be same as of Controllers.
Step 5: Add View popup show up. Name your view. Click on Use a layout page.
Your project folder structure should look like below.
If you note, a new HomeController.cs is added into Controller folder, Index.cshtml is added in Views > Home folder. You can find _ViewStart.cshtml and _Layout.cshtml files added in Shared folder. These are automatically added by Visual Studio and are partial views. The concept of Partial Views will be discussed later in this tutorial.
In the next part of tutorial you will learn about Bundling, Filtering and Routing in MVC.
Public profile: user/profile/99900001