Metodo EditorExtensions.Editor (HtmlHelper, String, String, String, Object) (System.Web.Mvc.Html)

Cambia visualizzazione:
ScriptFree
Riferimento a .NET Framework
Metodo EditorExtensions.Editor (HtmlHelper, String, String, String, Object)
Il presente articolo è stato tradotto manualmente. Per visualizzare questa pagina e contemporaneamente visualizzarne il contenuto in lingua inglese, passare alla visualizzazione semplificata.

Restituisce un elemento HTML input per ogni proprietà nell'oggetto rappresentato dall'espressione utilizzando il modello specificato, il nome di campo HTML e ulteriori dati della visualizzazione.

Spazio dei nomi:  System.Web.Mvc.Html
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)
Sintassi

Visual Basic - (Dichiarazione)
<ExtensionAttribute> _
Public Shared Function Editor ( _
	html As HtmlHelper, _
	expression As String, _
	templateName As String, _
	htmlFieldName As String, _
	additionalViewData As Object _
) As MvcHtmlString
Visual Basic (Utilizzo)
Dim html As HtmlHelper
Dim expression As String
Dim templateName As String
Dim htmlFieldName As String
Dim additionalViewData As Object
Dim returnValue As MvcHtmlString

returnValue = html.Editor(expression, _
	templateName, htmlFieldName, additionalViewData)
C#
public static MvcHtmlString Editor(
	this HtmlHelper html,
	string expression,
	string templateName,
	string htmlFieldName,
	Object additionalViewData
)
Visual C++
[ExtensionAttribute]
public:
static MvcHtmlString^ Editor(
	HtmlHelper^ html, 
	String^ expression, 
	String^ templateName, 
	String^ htmlFieldName, 
	Object^ additionalViewData
)
JScript
public static function Editor(
	html : HtmlHelper, 
	expression : String, 
	templateName : String, 
	htmlFieldName : String, 
	additionalViewData : Object
) : MvcHtmlString

Parametri

html
Tipo: System.Web.Mvc.HtmlHelper
Istanza dell'helper HTML estesa da questo metodo.
expression
Tipo: System.String
Espressione che identifica l'oggetto contenente le proprietà da visualizzare.
templateName
Tipo: System.String
Nome del modello da utilizzare per il rendering dell'oggetto.
htmlFieldName
Tipo: System.String
Stringa utilizzata per risolvere l'ambiguità dei nomi degli elementi HTML input di cui viene eseguito il rendering per le proprietà con lo stesso nome.
additionalViewData
Tipo: System.Object
Oggetto anonimo che può contenere ulteriori dati della visualizzazione che verranno uniti all'istanza di ViewDataDictionary<TModel> creata per il modello.

Valore restituito

Tipo: System.Web.Mvc.MvcHtmlString
Elemento HTML input per ogni proprietà nell'oggetto rappresentato dall'espressione.

Nota sull'utilizzo

In Visual Basic e C# è possibile chiamare questo metodo come metodo di istanza in qualsiasi oggetto di tipo HtmlHelper. Per chiamare il metodo utilizzando la sintassi del metodo di istanza, omettere il primo parametro. Per ulteriori informazioni, vedere b8020aae-374d-46a9-bcb7-8cc2390b93b6 o 175ce3ff-9bbf-4e64-8421-faeb81a0bb51.
Note

The htmlFieldName parameter is provided for the case in which all the following are true:

  • A page contains multiple objects to be edited.

  • The action method model binds each object separately.

  • The objects have at least one property that has the same name.

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.

Vedere anche

Riferimenti