ViewResult First Response

Represents a class that is used to render a view by using an IView instance that is returned by an IViewEngine object.

IView Interface

 


NameDescription
System_CAPS_pubmethodRender(ViewContext, TextWriter)
Renders the specified view context by using the specified the writer object.

IViewEngine Interface

 


NameDescription
System_CAPS_pubmethodFindPartialView(ControllerContext, String, Boolean)
Finds the specified partial view by using the specified controller context.
System_CAPS_pubmethodFindView(ControllerContext, String, String, Boolean)
Finds the specified view by using the specified controller context.
System_CAPS_pubmethodReleaseView(ControllerContext, IView)
Releases the specified view by using the specified controller context.

A view engine is called by the MVC framework to render view pages.

 


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.


Properties :: ---



NameDescription
System_CAPS_pubpropertyMasterName
Gets the name of the master view (such as a master page or template) to use when the view is rendered.
System_CAPS_pubpropertyModel
Gets the view data model.(Inherited from ViewResultBase.)
System_CAPS_pubpropertyTempData
Gets or sets the TempDataDictionary object for this result.(Inherited from ViewResultBase.)
System_CAPS_pubpropertyView
Gets or sets the IView object that is rendered to the response.(Inherited from ViewResultBase.)
System_CAPS_pubpropertyViewBag
Gets the view bag.(Inherited from ViewResultBase.)
System_CAPS_pubpropertyViewData
Gets or sets the view data ViewDataDictionary object for this result.(Inherited from ViewResultBase.)
System_CAPS_pubpropertyViewEngineCollection
Gets or sets the collection of view engines that are associated with this result.(Inherited from ViewResultBase.)
System_CAPS_pubpropertyViewName
Gets or sets the name of the view to render.(Inherited from ViewResultBase.)



NameDescription
System_CAPS_pubmethodEquals(Object)
(Inherited from Object.)
System_CAPS_pubmethodExecuteResult(ControllerContext)
When called by the action invoker, renders the view to the response.(Inherited from ViewResultBase.)
System_CAPS_protmethodFinalize()
(Inherited from Object.)
System_CAPS_protmethodFindView(ControllerContext)
Searches the registered view engines and returns the object that is used to render the view.(Overrides ViewResultBase.FindView(ControllerContext).)
System_CAPS_pubmethodGetHashCode()
(Inherited from Object.)
System_CAPS_pubmethodGetType()
(Inherited from Object.)
System_CAPS_protmethodMemberwiseClone()
(Inherited from Object.)
System_CAPS_pubmethodToString()
(Inherited from Object.)

Post a Comment

0 Comments