Export (0) Print
Expand All

DisplayExtensions Class

Represents support for rendering object values as HTML.

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

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

[<AbstractClassAttribute>]
[<SealedAttribute>]
type DisplayExtensions =  class end

  NameDescription
Public methodStatic memberDisplay(HtmlHelper, String)Returns HTML markup for each property in the object that is represented by a string expression.
Public methodStatic memberDisplay(HtmlHelper, String, Object)Returns HTML markup for each property in the object that is represented by a string expression, using additional view data.
Public methodStatic memberDisplay(HtmlHelper, String, String)Returns HTML markup for each property in the object that is represented by the expression, using the specified template.
Public methodStatic memberDisplay(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.
Public methodStatic memberDisplay(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.
Public methodStatic memberDisplay(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.
Public methodStatic memberDisplayFor(TModel, TValue)(HtmlHelper(TModel), Expression(Func(TModel, TValue)))Returns HTML markup for each property in the object that is represented by the Expression expression.
Public methodStatic memberDisplayFor(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.
Public methodStatic memberDisplayFor(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.
Public methodStatic memberDisplayFor(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.
Public methodStatic memberDisplayFor(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.
Public methodStatic memberDisplayFor(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.
Public methodStatic memberDisplayForModel(HtmlHelper)Returns HTML markup for each property in the model.
Public methodStatic memberDisplayForModel(HtmlHelper, Object)Returns HTML markup for each property in the model, using additional view data.
Public methodStatic memberDisplayForModel(HtmlHelper, String)Returns HTML markup for each property in the model using the specified template.
Public methodStatic memberDisplayForModel(HtmlHelper, String, Object)Returns HTML markup for each property in the model, using the specified template and additional view data.
Public methodStatic memberDisplayForModel(HtmlHelper, String, String)Returns HTML markup for each property in the model using the specified template and HTML field ID.
Public methodStatic memberDisplayForModel(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.
Top

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

  • The Display method, which takes a string that represents the object value to render.

  • The DisplayFor method, which takes a model object.

  • The DisplayForModel method, which uses the model implicitly.

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 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.

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 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.

No code example is currently available or this language may not be supported.

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 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.

No code example is currently available or this language may not be supported.

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:

A Visual Studio project with source code is available to accompany this topic: Download.

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