Returns HTML markup for each property in the object that is represented by the Expression expression.
<ExtensionAttribute> _ Public Shared Function DisplayFor(Of TModel, TValue) ( _ html As HtmlHelper(Of TModel), _ expression As Expression(Of Func(Of TModel, TValue)) _ ) As MvcHtmlString
public static MvcHtmlString DisplayFor<TModel, TValue>( this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression )
[ExtensionAttribute] public: generic<typename TModel, typename TValue> static MvcHtmlString^ DisplayFor( HtmlHelper<TModel>^ html, Expression<Func<TModel, TValue>^>^ expression )
The type of the model.
The type of the value.
This method is typically used to display values from the object that is exposed by the Model property. For more information about the differences between this method and the other Display methods, see the DisplayExtensions class overview.
This method generates different HTML markup depending on the data type of the property that is being rendered, and according to whether the property is marked with certain attributes. The method renders markup according to the following rules:
If the property is typed as a primitive type (integer, string, and so on), the method renders a string that represents the property value.
If the property type is Boolean, the method renders an HTML input element for a check box. For example, a Boolean property named Enabled might render markup such as the following:
<input class="check-box"
disabled="disabled"
type="checkbox"
checked="checked" />
If a property is annotated with a data type attribute, the attribute specifies the markup that is generated for the property. For example, if the property is marked with the EmailAddress attribute, the method generates markup that contains an HTML anchor that is configured with the mailto protocol, as in the following example:
<a href='mailto:joe@contoso.com'>joe@contoso.com</a>
If the object contains multiple properties, for each property the method generates a string that consists of markup for the property name and markup for the property value.
A Visual Studio project with source code is available to accompany this topic: Download.