View Result in Controller Sample in MVC: Day 11

Introduction

This article shows how to use view result in a Controller in MVC.

Step 1

Create a MVC project from the "Empty" template.

Right-click on "Controllers" and select "Add" >> "Controller...".



Step 2

Select "MVC 5 Controller - Empty" to add an empty Controller.

Click on the "Add" button.



Step 3

Name the Controller as in the following:



Step 4

Now we need to create a view.

Right-click on "Index" and select "Add View...".



Step 5

Name the view and select "Empty (without model)" as the template.

Click on the "Add" button.



Step 6

Add a title in the index page.



Step 7

ViewResult represents a class that is used to render a view by using an IView instance that is returned by an IViewEngine object. View() creates an object that renders a view to the response.



Step 8

Now we need to create a view.

Right-click on "About" and select "Add View...".



Step 9

Name the view and select "Empty (without model)" as the template.

Click on the "Add" button.



Step 10

Add the title in the about page.



Step 11

Add html.actionlink for about.cshtml.



Step 12

Run the project, click on the about link and you will see the about page rendered in the browser.



<< Day 10                                               >> Day 12


Similar Articles