Views in MVC
The Views folder stores the files
(HTML files) related to the display of the application (the user interfaces).
These files may have the extensions html, asp, aspx, cshtml, and vbhtml,
depending on the language content.The Views folder contains
one folder for each controller.
In the
Model-View-Controller (MVC) pattern, views are intended exclusively for
encapsulating presentation logic. They should not contain any application logic
or database retrieval code. All application logic should be handled by the
controller. A view renders the appropriate UI by using the data that is passed
to it from the controller. This data is passed to a view from a controller
action method by using the View method.
A view page is an
instance of the ViewPage class.
It inherits from the Page class
and implements the IViewDataContainer interface.
The ViewPage class
defines a ViewDataproperty
that returns a ViewDataDictionary object.
This property contains the data that the view should display.
The MVC framework uses
URL routing to determine which controller action to invoke, and the controller
action then decides which views to render.
Partial Views
A partial view enables
you to define a view that will be rendered inside a parent view. Partial views
are implemented as ASP.NET user controls (.ascx).
When a partial view is
instantiated, it gets its own copy of the ViewDataDictionary object that is
available to the parent view. The partial view therefore has access to the data
of the parent view. However, if the partial view updates the data, those
updates affect only the partial view's ViewData object. The
parent view's data is not changed.
The ASP.NET MVC
framework includes helper methods that provide an easy way to render HTML in a
view. This topic explains how to work with the most frequently used HTML
helper.
To render a view, you
call the View method
of the controller. To pass data to the view, you use the ViewData property
of the ViewPage class.
This property returns aViewDataDictionary object
that has case-insensitive string keys.
Comments
Post a Comment