DisplayExtensions.DisplayFor(Of TModel, TValue) Method (HtmlHelper(Of TModel), Expression(Of Func(Of 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.
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
'Declaration <ExtensionAttribute> _ Public Shared Function DisplayFor(Of TModel, TValue) ( _ html As HtmlHelper(Of TModel), _ expression As Expression(Of Func(Of TModel, TValue)), _ templateName As String, _ htmlFieldName As String _ ) As MvcHtmlString 'Usage Dim html As HtmlHelper(Of TModel) Dim expression As Expression(Of Func(Of TModel, TValue)) Dim templateName As String Dim htmlFieldName As String Dim returnValue As MvcHtmlString returnValue = html.DisplayFor(expression, _ templateName, htmlFieldName)
The type of the model.
The type of the value.
- Type: System.Web.Mvc.HtmlHelper(Of )
The HTML helper instance that this method extends.
- Type: System.Linq.Expressions.Expression(Of Func(Of , ))
An expression that identifies the object that contains the properties to display.
- Type: System.String
The name of the template that is used to render the object.
- Type: System.String
A string that is used to disambiguate the names of HTML input elements that are rendered for properties that have the same name.
Return ValueType: System.Web.Mvc.MvcHtmlString
The HTML markup for each property in the object that is represented by the expression.
Usage NoteIn Visual Basic and C#, you can call this method as an instance method on any object of type HtmlHelper(Of ). When you use instance method syntax to call this method, omit the first parameter. For more information, see https://msdn.microsoft.com/en-us/library/bb384936(v=vs.108) or https://msdn.microsoft.com/en-us/library/bb383977(v=vs.108).
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.
If a template whose name matches the templateName parameter is found in the controller's DisplayTemplates folder, that template is used to render the expression. If a template is not found in the controller's DisplayTemplates folder, the Views\Shared\DisplayTemplates is searched for a template that matches the name of the templateName parameter. If no template is found, the default template is used.
The htmlFieldId parameter is used with HTML input when two properties in the model have the same name. The htmlFieldId parameter is used to disambiguate the two properties that have the same name.
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:
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:
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.