Please enable Javascript for better experience...
Adding Controller and Views to MVC
By Rahul Kumar Jha | Jan 15, 2015 | In Tutorials | Total Views [ 23441 ]
Taged In
(5 Like)
Rate

In this part of tutorial you will learn about adding controllers and views in MVC application.

Introduction

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.

Adding Controllers

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.

Adding Views

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.

<< Getting started-Create your first MVC application step by step
BundleConfig, FilterConfig and RouteConfig in MVC >>

Share this

About the Author

Rahul Kumar Jha
Rahul Kumar Jha
Founder, Developer dotnet-concept.com

Public profile: user/profile/99900001


Has working experience in different phases of Software Development Life Cycle (SDLC) in CMS, Gaming, Health Care and Financial Services domain using Agile pattern. Working experience in Design patterns, ASP.NET, MVC, ANGULAR, ANGULAR JS, Windows application, WCF, ADO.NET, SQL Server and Test Driven Development (TDD) environment with JQuery, JavaScript, N-Unit, Entity Frameworks, LINQ, Code Refactoring and Business Objects Models.

User's Comments


 
Please SignUp/Login to comment...

Or comment as anonymous...
* Name
* Email ID
Comment
 
 
 
 
 
 
Sponsors