Represents a class that is used to render a view by using an IView instance that is returned by an IViewEngine object.
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 :: ---
IView Interface
Name | Description | |
---|---|---|
Render(ViewContext, TextWriter) |
Renders the specified view context by using the specified the writer object.
|
IViewEngine Interface
Name | Description | |
---|---|---|
FindPartialView(ControllerContext, String, Boolean) |
Finds the specified partial view by using the specified controller context.
| |
FindView(ControllerContext, String, String, Boolean) |
Finds the specified view by using the specified controller context.
| |
ReleaseView(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 :: ---
Name | Description | |
---|---|---|
MasterName |
Gets the name of the master view (such as a master page or template) to use when the view is rendered.
| |
Model |
Gets the view data model.(Inherited from ViewResultBase.)
| |
TempData |
Gets or sets the TempDataDictionary object for this result.(Inherited from ViewResultBase.)
| |
View |
Gets or sets the IView object that is rendered to the response.(Inherited from ViewResultBase.)
| |
ViewBag |
Gets the view bag.(Inherited from ViewResultBase.)
| |
ViewData |
Gets or sets the view data ViewDataDictionary object for this result.(Inherited from ViewResultBase.)
| |
ViewEngineCollection |
Gets or sets the collection of view engines that are associated with this result.(Inherited from ViewResultBase.)
| |
ViewName |
Gets or sets the name of the view to render.(Inherited from ViewResultBase.)
|
Name | Description | |
---|---|---|
Equals(Object) |
(Inherited from Object.)
| |
ExecuteResult(ControllerContext) |
When called by the action invoker, renders the view to the response.(Inherited from ViewResultBase.)
| |
Finalize() |
(Inherited from Object.)
| |
FindView(ControllerContext) |
Searches the registered view engines and returns the object that is used to render the view.(Overrides ViewResultBase.FindView(ControllerContext).)
| |
GetHashCode() |
(Inherited from Object.)
| |
GetType() |
(Inherited from Object.)
| |
MemberwiseClone() |
(Inherited from Object.)
| |
ToString() |
(Inherited from Object.)
|
0 Comments