EditorExtensions.EditorFor Method

 

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)

Overload List

Name Description
System_CAPS_pubmethodSystem_CAPS_static EditorFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>)

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

System_CAPS_pubmethodSystem_CAPS_static EditorFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, Object)

Returns an HTML input element for each property in the object that is represented by the expression, using additional view data.

System_CAPS_pubmethodSystem_CAPS_static EditorFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String)

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

System_CAPS_pubmethodSystem_CAPS_static EditorFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, Object)

Returns an HTML input element for each property in the object that is represented by the expression, using the specified template and additional view data.

System_CAPS_pubmethodSystem_CAPS_static EditorFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, String)

Returns an HTML input element for each property in the object that is represented by the Expression expression, using the specified template and HTML field name.

System_CAPS_pubmethodSystem_CAPS_static EditorFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, String, Object)

Returns an HTML input element for each property in the object that is represented by the expression, using the specified template, HTML field name, and additional view data.

See Also

EditorExtensions Class
System.Web.Mvc.Html Namespace

Return to top

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.

Syntax

public static MvcHtmlString EditorFor<TModel, TValue>(
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression
)
public:
generic<typename TModel, typename TValue>
[ExtensionAttribute]
static MvcHtmlString^ EditorFor(
    HtmlHelper<TModel>^ html,
    Expression<Func<TModel, TValue>^>^ expression
)
static member EditorFor<'TModel, 'TValue> : 
        html:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TValue>> -> MvcHtmlString
<ExtensionAttribute>
Public Shared Function EditorFor(Of TModel, TValue) (
    html As HtmlHelper(Of TModel),
    expression As Expression(Of Func(Of TModel, TValue))
) As MvcHtmlString

Parameters

Return Value

Type: System.Web.Mvc.MvcHtmlString

An HTML input element for each property in the object that is represented by the expression.

Type Parameters

  • TModel
    The type of the model.
  • TValue
    The type of the value.

Remarks

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.

Return to top

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

Returns an HTML input element for each property in the object that is represented by the expression, using additional view data.

Syntax

public static MvcHtmlString EditorFor<TModel, TValue>(
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression,
    object additionalViewData
)
public:
generic<typename TModel, typename TValue>
[ExtensionAttribute]
static MvcHtmlString^ EditorFor(
    HtmlHelper<TModel>^ html,
    Expression<Func<TModel, TValue>^>^ expression,
    Object^ additionalViewData
)
static member EditorFor<'TModel, 'TValue> : 
        html:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TValue>> *
        additionalViewData:Object -> MvcHtmlString
<ExtensionAttribute>
Public Shared Function EditorFor(Of TModel, TValue) (
    html As HtmlHelper(Of TModel),
    expression As Expression(Of Func(Of TModel, TValue)),
    additionalViewData As Object
) As MvcHtmlString

Parameters

  • additionalViewData
    Type: System.Object

    An anonymous object that can contain additional view data that will be merged into the ViewDataDictionary<TModel> instance that is created for the template.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An HTML input element for each property in the object that is represented by the expression.

Type Parameters

  • TModel
    The type of the model.
  • TValue
    The type of the value.

Return to top

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

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

Syntax

public static MvcHtmlString EditorFor<TModel, TValue>(
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression,
    string templateName
)
public:
generic<typename TModel, typename TValue>
[ExtensionAttribute]
static MvcHtmlString^ EditorFor(
    HtmlHelper<TModel>^ html,
    Expression<Func<TModel, TValue>^>^ expression,
    String^ templateName
)
static member EditorFor<'TModel, 'TValue> : 
        html:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TValue>> *
        templateName:string -> MvcHtmlString
<ExtensionAttribute>
Public Shared Function EditorFor(Of TModel, TValue) (
    html As HtmlHelper(Of TModel),
    expression As Expression(Of Func(Of TModel, TValue)),
    templateName As String
) As MvcHtmlString

Parameters

  • templateName
    Type: System.String

    The name of the template to use to render the object.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An HTML input element for each property in the object that is represented by the expression.

Type Parameters

  • TModel
    The type of the model.
  • TValue
    The type of the value.

Remarks

If a template whose name matches the templateName parameter is found in the controller's EditorTemplates folder, that template is used to render the expression. If a template is not found in the controller's EditorTemplates folder, the Views\Shared\EditorTemplates folder is searched for a template that matches the name of the templateName parameter. If no template is found, the default template is used.

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 modify the property value.

Return to top

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

Returns an HTML input element for each property in the object that is represented by the expression, using the specified template and additional view data.

Syntax

public static MvcHtmlString EditorFor<TModel, TValue>(
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression,
    string templateName,
    object additionalViewData
)
public:
generic<typename TModel, typename TValue>
[ExtensionAttribute]
static MvcHtmlString^ EditorFor(
    HtmlHelper<TModel>^ html,
    Expression<Func<TModel, TValue>^>^ expression,
    String^ templateName,
    Object^ additionalViewData
)
static member EditorFor<'TModel, 'TValue> : 
        html:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TValue>> *
        templateName:string *
        additionalViewData:Object -> MvcHtmlString
<ExtensionAttribute>
Public Shared Function EditorFor(Of TModel, TValue) (
    html As HtmlHelper(Of TModel),
    expression As Expression(Of Func(Of TModel, TValue)),
    templateName As String,
    additionalViewData As Object
) As MvcHtmlString

Parameters

  • templateName
    Type: System.String

    The name of the template to use to render the object.

  • additionalViewData
    Type: System.Object

    An anonymous object that can contain additional view data that will be merged into the ViewDataDictionary<TModel> instance that is created for the template.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An HTML input element for each property in the object that is represented by the expression.

Type Parameters

  • TModel
    The type of the model.
  • TValue
    The type of the value.

Return to top

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

Returns an HTML input element for each property in the object that is represented by the Expression expression, using the specified template and HTML field name.

Syntax

public static MvcHtmlString EditorFor<TModel, TValue>(
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression,
    string templateName,
    string htmlFieldName
)
public:
generic<typename TModel, typename TValue>
[ExtensionAttribute]
static MvcHtmlString^ EditorFor(
    HtmlHelper<TModel>^ html,
    Expression<Func<TModel, TValue>^>^ expression,
    String^ templateName,
    String^ htmlFieldName
)
static member EditorFor<'TModel, 'TValue> : 
        html:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TValue>> *
        templateName:string *
        htmlFieldName:string -> MvcHtmlString
<ExtensionAttribute>
Public Shared Function EditorFor(Of TModel, TValue) (
    html As HtmlHelper(Of TModel),
    expression As Expression(Of Func(Of TModel, TValue)),
    templateName As String,
    htmlFieldName As String
) As MvcHtmlString

Parameters

  • templateName
    Type: System.String

    The name of the template to use to render the object.

  • htmlFieldName
    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 Value

Type: System.Web.Mvc.MvcHtmlString

An HTML input element for each property in the object that is represented by the expression.

Type Parameters

  • TModel
    The type of the model.
  • TValue
    The type of the value.

Return to top

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

Returns an HTML input element for each property in the object that is represented by the expression, using the specified template, HTML field name, and additional view data.

Syntax

public static MvcHtmlString EditorFor<TModel, TValue>(
    this HtmlHelper<TModel> html,
    Expression<Func<TModel, TValue>> expression,
    string templateName,
    string htmlFieldName,
    object additionalViewData
)
public:
generic<typename TModel, typename TValue>
[ExtensionAttribute]
static MvcHtmlString^ EditorFor(
    HtmlHelper<TModel>^ html,
    Expression<Func<TModel, TValue>^>^ expression,
    String^ templateName,
    String^ htmlFieldName,
    Object^ additionalViewData
)
static member EditorFor<'TModel, 'TValue> : 
        html:HtmlHelper<'TModel> *
        expression:Expression<Func<'TModel, 'TValue>> *
        templateName:string *
        htmlFieldName:string *
        additionalViewData:Object -> MvcHtmlString
<ExtensionAttribute>
Public Shared Function EditorFor(Of TModel, TValue) (
    html As HtmlHelper(Of TModel),
    expression As Expression(Of Func(Of TModel, TValue)),
    templateName As String,
    htmlFieldName As String,
    additionalViewData As Object
) As MvcHtmlString

Parameters

  • templateName
    Type: System.String

    The name of the template to use to render the object.

  • htmlFieldName
    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.

  • additionalViewData
    Type: System.Object

    An anonymous object that can contain additional view data that will be merged into the ViewDataDictionary<TModel> instance that is created for the template.

Return Value

Type: System.Web.Mvc.MvcHtmlString

An HTML input element for each property in the object that is represented by the expression.

Type Parameters

  • TModel
    The type of the model.
  • TValue
    The type of the value.

Return to top