Share via


IHtmlHelper<TModel>.DisplayFor<TResult> Method

Definition

Returns HTML markup for the expression, using a display template, specified HTML field name, and additional view data. The template name is taken from the templateName or the expression’s TemplateHint. If the template file is not found, a default template will be used.

public:
generic <typename TResult>
 Microsoft::AspNetCore::Html::IHtmlContent ^ DisplayFor(System::Linq::Expressions::Expression<Func<TModel, TResult> ^> ^ expression, System::String ^ templateName, System::String ^ htmlFieldName, System::Object ^ additionalViewData);
public Microsoft.AspNetCore.Html.IHtmlContent DisplayFor<TResult> (System.Linq.Expressions.Expression<Func<TModel,TResult>> expression, string templateName, string htmlFieldName, object additionalViewData);
abstract member DisplayFor : System.Linq.Expressions.Expression<Func<'Model, 'Result>> * string * string * obj -> Microsoft.AspNetCore.Html.IHtmlContent
Public Function DisplayFor(Of TResult) (expression As Expression(Of Func(Of TModel, TResult)), templateName As String, htmlFieldName As String, additionalViewData As Object) As IHtmlContent

Type Parameters

TResult

The type of the expression result.

Parameters

expression
Expression<Func<TModel,TResult>>

An expression to be evaluated against the current model.

templateName
String

The name of the template used to create the HTML markup.

htmlFieldName
String

A String used to disambiguate the names of HTML elements that are created for properties that have the same name.

additionalViewData
Object

An anonymous Object or IDictionary<TKey,TValue> that can contain additional view data that will be merged into the ViewDataDictionary<TModel> instance created for the template.

Returns

A new IHtmlContent containing the created HTML.

Remarks

For example the default Object display template includes markup for each property in the expression result.

Custom templates are found under a DisplayTemplates folder within the Pages folder. The folder name is case-sensitive on case-sensitive file systems.

Applies to