EditorExtensions.EditorForModel Method (HtmlHelper, String)

Returns an HTML input element for each property in the model, using the specified template.

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


<ExtensionAttribute> _
Public Shared Function EditorForModel ( _
    html As HtmlHelper, _
    templateName As String _
) As MvcHtmlString
Dim html As HtmlHelper 
Dim templateName As String 
Dim returnValue As MvcHtmlString 

returnValue = html.EditorForModel(templateName)
public static MvcHtmlString EditorForModel(
    this HtmlHelper html,
    string templateName
static MvcHtmlString^ EditorForModel(
    HtmlHelper^ html, 
    String^ templateName
static member EditorForModel : 
        html:HtmlHelper * 
        templateName:string -> MvcHtmlString
public static function EditorForModel(
    html : HtmlHelper, 
    templateName : String
) : MvcHtmlString


  • 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 model and in the specified template.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type HtmlHelper. 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).


If a template whose name matches the templateName parameter is found in the controller's EditorTemplates folder, that template is used to render the model. 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"






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


A Visual Studio project with source code is available to accompany this topic: Download.

See Also


EditorExtensions Class

EditorForModel Overload

System.Web.Mvc.Html Namespace