DisplayExtensions Class

 

Represents support for rendering object values as HTML.

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

System.Object
  System.Web.Mvc.Html.DisplayExtensions

public static class DisplayExtensions

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticDisplay(HtmlHelper, String)

Returns HTML markup for each property in the object that is represented by a string expression.

System_CAPS_pubmethodSystem_CAPS_staticDisplay(HtmlHelper, String, Object)

Returns HTML markup for each property in the object that is represented by a string expression, using additional view data.

System_CAPS_pubmethodSystem_CAPS_staticDisplay(HtmlHelper, String, String)

Returns HTML markup for each property in the object that is represented by the expression, using the specified template.

System_CAPS_pubmethodSystem_CAPS_staticDisplay(HtmlHelper, String, String, Object)

Returns HTML markup for each property in the object that is represented by the expression, using the specified template and additional view data.

System_CAPS_pubmethodSystem_CAPS_staticDisplay(HtmlHelper, String, String, String)

Returns HTML markup for each property in the object that is represented by the expression, using the specified template and an HTML field ID.

System_CAPS_pubmethodSystem_CAPS_staticDisplay(HtmlHelper, String, String, String, Object)

Returns HTML markup for each property in the object that is represented by the expression, using the specified template, HTML field ID, and additional view data.

System_CAPS_pubmethodSystem_CAPS_staticDisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>)

Returns HTML markup for each property in the object that is represented by the Expression expression.

System_CAPS_pubmethodSystem_CAPS_staticDisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, Object)

Returns a string that contains each property value in the object that is represented by the specified expression, using additional view data.

System_CAPS_pubmethodSystem_CAPS_staticDisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String)

Returns a string that contains each property value in the object that is represented by the Expression, using the specified template.

System_CAPS_pubmethodSystem_CAPS_staticDisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, Object)

Returns a string that contains each property value in the object that is represented by the specified expression, using the specified template and additional view data.

System_CAPS_pubmethodSystem_CAPS_staticDisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, String)

Returns HTML markup for each property in the object that is represented by the Expression, using the specified template and an HTML field ID.

System_CAPS_pubmethodSystem_CAPS_staticDisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, String, Object)

Returns HTML markup for each property in the object that is represented by the specified expression, using the template, an HTML field ID, and additional view data.

System_CAPS_pubmethodSystem_CAPS_staticDisplayForModel(HtmlHelper)

Returns HTML markup for each property in the model.

System_CAPS_pubmethodSystem_CAPS_staticDisplayForModel(HtmlHelper, Object)

Returns HTML markup for each property in the model, using additional view data.

System_CAPS_pubmethodSystem_CAPS_staticDisplayForModel(HtmlHelper, String)

Returns HTML markup for each property in the model using the specified template.

System_CAPS_pubmethodSystem_CAPS_staticDisplayForModel(HtmlHelper, String, Object)

Returns HTML markup for each property in the model, using the specified template and additional view data.

System_CAPS_pubmethodSystem_CAPS_staticDisplayForModel(HtmlHelper, String, String)

Returns HTML markup for each property in the model using the specified template and HTML field ID.

System_CAPS_pubmethodSystem_CAPS_staticDisplayForModel(HtmlHelper, String, String, Object)

Returns HTML markup for each property in the model, using the specified template, an HTML field ID, and additional view data.

The DisplayExtensions class provides the following methods that let you render values as HTML:

You can use the Display method to display data from the ViewData dictionary and from the object that is exposed by the Model property. If you do not know the type of the object that is exposed by the Model property, use the Display method.

The DisplayFor<TModel, TValue> and DisplayForModel methods are typically used to display values from the object that is exposed by the Model property. You can also use these methods to display values from an object other than that exposed by the Model or ViewData properties.

System_CAPS_noteNote

The two methods are often used in loop structures to render values from a collection of objects. The IndexPals.aspx page from the downloadable sample shows how to use the DisplayFor<TModel, TValue> method in a loop.

The following example shows how to display a value that is not in the object that is exposed by the Model property.

<% var cv = Html.ViewContext.ClientValidationEnabled;  %> 
<%= Html.DisplayFor(model => cv) %>

The model expressions that are passed to the methods are helpers that operate on the current model. The DisplayForModel call is functionally equivalent to calling the DisplayFor<TModel, TValue> method and passing a model as a parameter. The following examples shows how to use each of these methods. The value that is rendered for each method is the same.

<%= Html.DisplayForModel() %>
<%= Html.DisplayFor(model => cv) %>

The DisplayExtensions class uses the ViewEngineCollection instance to resolve which view to pass the model into. Therefore, you can write display templates for any view engine. For more information on alternative view engines see the following links:

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

Return to top
Show: