RenderPartialExtensions Class

Provides support for rendering a partial view.


Namespace:  System.Web.Mvc.Html
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

public static class RenderPartialExtensions

Public methodStatic memberRenderPartial(HtmlHelper, String)Renders the specified partial view by using the specified HTML helper.
Public methodStatic memberRenderPartial(HtmlHelper, String, Object)Renders the specified partial view, passing it a copy of the current ViewDataDictionary object, but with the Model property set to the specified model.
Public methodStatic memberRenderPartial(HtmlHelper, String, ViewDataDictionary)Renders the specified partial view, replacing its ViewData property with the specified ViewDataDictionary object.
Public methodStatic memberRenderPartial(HtmlHelper, String, Object, ViewDataDictionary)Renders the specified partial view, replacing the partial view's ViewData property with the specified ViewDataDictionary object and setting the Model property of the view data to the specified model.

The RenderPartialExtensions class contains methods that extend the HtmlHelper class. The RenderPartial method renders an ASP.NET user control (.ascx file) as a partial view.

The following example shows how to create a partial view as a user control (.ascx file). The control displays the date and time strings that are passed in the ViewDataDictionary object. The control also calls the ActionLink helper method to refresh the date and time.

In the following example, the Index action method initializes the date and time strings and renders the Index view.

The following Index view shows how to use the RenderPartial helper method to display the partial view within its parent view. Unlike other HTML helper methods, a call to the RenderPartial method is enclosed in <% %> characters instead of <%= %> characters. This is because the RenderPartial method renders directly to the output stream. In contrast, most other helper methods return a string.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.