Export (0) Print
Expand All

EditorExtensions.EditorFor<TModel, TValue> Method (HtmlHelper<TModel>, Expression<Func<TModel, TValue>>)

Returns an HTML input element for each property in the object that is represented by the Expression expression.

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

public static MvcHtmlString EditorFor<TModel, TValue>(
	this HtmlHelper<TModel> html,
	Expression<Func<TModel, TValue>> expression
)

Type Parameters

TModel

The type of the model.

TValue

The type of the value.

Parameters

html
Type: System.Web.Mvc.HtmlHelper<TModel>
The HTML helper instance that this method extends.
expression
Type: System.Linq.Expressions.Expression<Func<TModel, TValue>>
An expression that identifies the object that contains the properties to display.

Return Value

Type: System.Web.Mvc.MvcHtmlString
An HTML input element for each property in the object that is represented by the expression.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type HtmlHelper<TModel>. When you use instance method syntax to call this method, omit the first parameter. For more information, see http://msdn.microsoft.com/en-us/library/bb384936.aspx or http://msdn.microsoft.com/en-us/library/bb383977.aspx.

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 an HTML input element for a text box. For example, a property named Height that is typed as a integer might render markup such as the following:

    <input class="text-box single-line"

    id="Height"

    name="Height"

    type="text"

    value="68"

    />

  • If a property is marked with a data-type attribute or a UIHintAttribute attribute, the attribute specifies the markup that is generated for the property. For example, if the property is marked with the MultilineText attribute, the method generates markup for a multi-line text box.

  • If the object contains multiple properties, for each property, the method generates a string that consists of markup for the property name and an input element to edit the property value.

Show:
© 2014 Microsoft