Rappresenta il supporto per il rendering di valori dell'oggetto in formato HTML.
System.Web.Mvc.Html.DisplayExtensions
Spazio dei nomi: System.Web.Mvc.Html
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
<ExtensionAttribute> _ Public NotInheritable Class DisplayExtensions
Non è necessario dichiarare un'istanza di una classe statica per accedere ai relativi membri.
public static class DisplayExtensions
[ExtensionAttribute] public ref class DisplayExtensions abstract sealed
public final class DisplayExtensions
| Nome | Descrizione | |
|---|---|---|
|
Display(HtmlHelper, String) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato da un'espressione stringa. |
|
Display(HtmlHelper, String, Object) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato da un'espressione stringa utilizzando ulteriori dati della visualizzazione. |
|
Display(HtmlHelper, String, String) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato dall'espressione, utilizzando il modello specificato. |
|
Display(HtmlHelper, String, String, Object) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato dall'espressione utilizzando il modello specificato e ulteriori dati della visualizzazione. |
|
Display(HtmlHelper, String, String, String) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato dall'espressione, utilizzando il modello specificato e l'ID di un campo HTML. |
|
Display(HtmlHelper, String, String, String, Object) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato dall'espressione utilizzando il modello specificato, l'ID del campo HTML e ulteriori dati della visualizzazione. |
|
DisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato dall'espressione Expression. |
|
DisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, Object) | Restituisce una stringa che contiene il valore di ogni proprietà nell'oggetto rappresentato dall'espressione specificata utilizzando ulteriori dati della visualizzazione. |
|
DisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String) | Restituisce una stringa contenente il valore di ogni proprietà nell'oggetto rappresentato da Expression, utilizzando il modello specificato. |
|
DisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, Object) | Restituisce una stringa che contiene il valore di ogni proprietà nell'oggetto rappresentato dall'espressione specificata utilizzando il modello specificato e ulteriori dati della visualizzazione. |
|
DisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, String) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato da Expression, utilizzando il modello specificato e l'ID di un campo HTML. |
|
DisplayFor<TModel, TValue>(HtmlHelper<TModel>, Expression<Func<TModel, TValue>>, String, String, Object) | Restituisce il markup HTML per ogni proprietà nell'oggetto rappresentato dall'espressione specificata utilizzando il modello, l'ID di un campo HTML e ulteriori dati della visualizzazione. |
|
DisplayForModel(HtmlHelper) | Restituisce il markup HTML per ogni proprietà nel modello. |
|
DisplayForModel(HtmlHelper, Object) | Restituisce il markup HTML per ogni proprietà nel modello utilizzando ulteriori dati della visualizzazione. |
|
DisplayForModel(HtmlHelper, String) | Restituisce il markup HTML per ogni proprietà nel modello utilizzando il modello specificato. |
|
DisplayForModel(HtmlHelper, String, Object) | Restituisce il markup HTML per ogni proprietà nel modello utilizzando il modello specificato e ulteriori dati della visualizzazione. |
|
DisplayForModel(HtmlHelper, String, String) | Restituisce il markup HTML per ogni proprietà nel modello utilizzando il modello e l'ID di un campo HTML specificati. |
|
DisplayForModel(HtmlHelper, String, String, Object) | Restituisce il markup HTML per ogni proprietà nel modello utilizzando il modello specificato, l'ID di un campo HTML e ulteriori dati della visualizzazione. |
The DisplayExtensions class provides the following methods that let you render values as HTML:
-
The Display method, which takes a string that represents the object value to render.
-
The DisplayFor method, which takes a model object.
-
The DisplayForModel method, which uses the model implicitly.
You can use the Display method to display data from the ViewData dictionary and from the object that is exposed by the Model property. If you do not know the type of the object that is exposed by the Model property, use the Display method.
The DisplayFor and DisplayForModel methods are typically used to display values from the object that is exposed by the Model property. You can also use these methods to display values from an object other than that exposed by the Model or ViewData properties.
Nota:
|
|---|
|
The two methods are often used in loop structures to render values from a collection of objects. The IndexPals.aspx page from the downloadable sample shows how to use the DisplayFor method in a loop. |
The following example shows how to display a value that is not in the object that is exposed by the Model property.
<% var cv = Html.ViewContext.ClientValidationEnabled; %>
<%= Html.DisplayFor(model => cv) %>
<% Dim cv = Html.ViewContext.ClientValidationEnabled %> <%=Html.DisplayFor(Function(c) cv)%>
The model expressions that are passed to the methods are helpers that operate on the current model. The DisplayForModel call is functionally equivalent to calling the DisplayFor method and passing a model as a parameter. The following examples shows how to use each of these methods. The value that is rendered for each method is the same.
<%= Html.DisplayForModel() %> <%= Html.DisplayFor(model => cv) %>
<%=Html.DisplayForModel()%>
<%=Html.DisplayFor(Function(c) cv)%>
The DisplayExtensions class uses the ViewEngineCollection instance to resolve which view to pass the model into. Therefore, you can write display templates for any view engine. For more information on alternative view engines see the following links:
A Visual Studio project with source code is available to accompany this topic: Download.
Nota: