HtmlHelperDisplayExtensions.DisplayFor Method

Definition

Overloads

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>)

Returns HTML markup for the expression, using a display template. The template is found using the expression's ModelMetadata.

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, Object)

Returns HTML markup for the expression, using a display template and specified additional view data. The template is found using the expression's ModelMetadata.

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, String)

Returns HTML markup for the expression, using a display template. The template is found using the templateName or the expression's ModelMetadata.

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, String, Object)

Returns HTML markup for the expression, using a display template and specified additional view data. The template is found using the templateName or the expression's ModelMetadata.

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, String, String)

Returns HTML markup for the expression, using a display template and specified HTML field name. The template is found using the templateName or the expression's ModelMetadata.

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>)

Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs

Returns HTML markup for the expression, using a display template. The template is found using the expression's ModelMetadata.

C#
public static Microsoft.AspNetCore.Html.IHtmlContent DisplayFor<TModel,TResult> (this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> htmlHelper, System.Linq.Expressions.Expression<Func<TModel,TResult>> expression);

Type Parameters

TModel

The type of the model.

TResult

The type of the expression result.

Parameters

htmlHelper
IHtmlHelper<TModel>

The IHtmlHelper<TModel> instance this method extends.

expression
Expression<Func<TModel,TResult>>

An expression to be evaluated against the current model.

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. The folder name is case-sensitive on case-sensitive file systems.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, Object)

Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs

Returns HTML markup for the expression, using a display template and specified additional view data. The template is found using the expression's ModelMetadata.

C#
public static Microsoft.AspNetCore.Html.IHtmlContent DisplayFor<TModel,TResult> (this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> htmlHelper, System.Linq.Expressions.Expression<Func<TModel,TResult>> expression, object additionalViewData);

Type Parameters

TModel

The type of the model.

TResult

The type of the expression result.

Parameters

htmlHelper
IHtmlHelper<TModel>

The IHtmlHelper<TModel> instance this method extends.

expression
Expression<Func<TModel,TResult>>

An expression to be evaluated against the current model.

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. The folder name is case-sensitive on case-sensitive file systems.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, String)

Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs

Returns HTML markup for the expression, using a display template. The template is found using the templateName or the expression's ModelMetadata.

C#
public static Microsoft.AspNetCore.Html.IHtmlContent DisplayFor<TModel,TResult> (this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> htmlHelper, System.Linq.Expressions.Expression<Func<TModel,TResult>> expression, string templateName);

Type Parameters

TModel

The type of the model.

TResult

The type of the expression result.

Parameters

htmlHelper
IHtmlHelper<TModel>

The IHtmlHelper<TModel> instance this method extends.

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.

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. The folder name is case-sensitive on case-sensitive file systems.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, String, Object)

Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs

Returns HTML markup for the expression, using a display template and specified additional view data. The template is found using the templateName or the expression's ModelMetadata.

C#
public static Microsoft.AspNetCore.Html.IHtmlContent DisplayFor<TModel,TResult> (this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> htmlHelper, System.Linq.Expressions.Expression<Func<TModel,TResult>> expression, string templateName, object additionalViewData);

Type Parameters

TModel

The type of the model.

TResult

The type of the expression result.

Parameters

htmlHelper
IHtmlHelper<TModel>

The IHtmlHelper<TModel> instance this method extends.

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.

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. The folder name is case-sensitive on case-sensitive file systems.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

DisplayFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, String, String)

Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs
Source:
HtmlHelperDisplayExtensions.cs

Returns HTML markup for the expression, using a display template and specified HTML field name. The template is found using the templateName or the expression's ModelMetadata.

C#
public static Microsoft.AspNetCore.Html.IHtmlContent DisplayFor<TModel,TResult> (this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> htmlHelper, System.Linq.Expressions.Expression<Func<TModel,TResult>> expression, string templateName, string htmlFieldName);

Type Parameters

TModel

The type of the model.

TResult

The type of the expression result.

Parameters

htmlHelper
IHtmlHelper<TModel>

The IHtmlHelper<TModel> instance this method extends.

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.

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. The folder name is case-sensitive on case-sensitive file systems.

Applies to

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0