HtmlHelper Class

Provides support for rendering HTML form controls and performing form validation in a web page.

Inheritance Hierarchy

System.Object
  System.Web.WebPages.Html.HtmlHelper

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

Syntax

'Declaration
Public Class HtmlHelper
'Usage
Dim instance As HtmlHelper
public class HtmlHelper
public ref class HtmlHelper
type HtmlHelper =  class end
public class HtmlHelper

The HtmlHelper type exposes the following members.

Properties

  Name Description
Public propertyStatic member IdAttributeDotReplacement Gets or sets the character that is used to replace the dot (.) in the id attribute of rendered form controls.
Public propertyStatic member UnobtrusiveJavaScriptEnabled Gets or sets a value that indicates whether the page uses unobtrusive JavaScript for Ajax functionality.
Public propertyStatic member ValidationInputCssClassName Gets or sets the name of the CSS class that defines the appearance of input elements when validation fails.
Public propertyStatic member ValidationInputValidCssClassName Gets or sets the name of the CSS class that defines the appearance of input elements when validation passes.
Public propertyStatic member ValidationMessageCssClassName Gets or sets the name of the CSS class that defines the appearance of validation error messages when validation fails.
Public propertyStatic member ValidationMessageValidCssClassName Gets or sets the name of the CSS class that defines the appearance of validation error messages when validation passes.
Public propertyStatic member ValidationSummaryClass Gets or sets the name of the CSS class that defines the appearance of a validation summary when validation fails.
Public propertyStatic member ValidationSummaryValidClass Gets or sets the name of the CSS class that defines the appearance of a validation summary when validation passes.

Top

Methods

  Name Description
Public methodStatic member AnonymousObjectToHtmlAttributes Creates a dictionary of HTML attributes from the input object, translating underscores to dashes.
Public method AttributeEncode(Object) Returns an HTML-encoded string that represents the specified object by using a minimal encoding that is suitable only for HTML attributes that are enclosed in quotation marks.
Public method AttributeEncode(String) Returns an HTML-encoded string that represents the specified string by using a minimal encoding that is suitable only for HTML attributes that are enclosed in quotation marks.
Public method CheckBox(String) Returns an HTML check box control that has the specified name.
Public method CheckBox(String, Boolean) Returns an HTML check box control that has the specified name and default checked status.
Public method CheckBox(String, IDictionary<String, Object>) Returns an HTML check box control that has the specified name and custom attributes defined by an attribute dictionary.
Public method CheckBox(String, Object) Returns an HTML check box control that has the specified name and custom attributes defined by an attribute object.
Public method CheckBox(String, Boolean, IDictionary<String, Object>) Returns an HTML check box control that has the specified name, default checked status, and custom attributes defined by an attribute dictionary.
Public method CheckBox(String, Boolean, Object) Returns an HTML check box control that has the specified name, default checked status, and custom attributes defined by an attribute object.
Public method DropDownList(String, IEnumerable<SelectListItem>) Returns an HTML drop-down list control that has the specified name and that contains the specified list items.
Public method DropDownList(String, IEnumerable<SelectListItem>, IDictionary<String, Object>) Returns an HTML drop-down list control that has the specified name and custom attributes defined by an attribute dictionary, and that contains the specified list items.
Public method DropDownList(String, IEnumerable<SelectListItem>, Object) Returns an HTML drop-down list control that has the specified name and custom attributes defined by an attribute object, and that contains the specified list items.
Public method DropDownList(String, String, IEnumerable<SelectListItem>) Returns an HTML drop-down list control that has the specified name, and that contains the specified list items and default item.
Public method DropDownList(String, String, IEnumerable<SelectListItem>, IDictionary<String, Object>) Returns an HTML drop-down list control that has the specified name and custom attributes defined by an attribute dictionary, and that contains the specified list items and default item.
Public method DropDownList(String, String, IEnumerable<SelectListItem>, Object) Returns an HTML drop-down list control that has the specified name and custom attributes defined by an attribute object, and that contains the specified list items and default item.
Public method DropDownList(String, String, IEnumerable<SelectListItem>, Object, IDictionary<String, Object>) Returns an HTML drop-down list control that has the specified name, custom attributes defined by an attribute dictionary, and default selection, and that contains the specified list items and default item.
Public method DropDownList(String, String, IEnumerable<SelectListItem>, Object, Object) Returns an HTML drop-down list control that has the specified name, custom attributes defined by an attribute object, and default selection, and that contains the specified list items and default item.
Public method Encode(Object) Returns an HTML-encoded string that represents the specified object by using a full encoding that is suitable for arbitrary HTML.
Public method Encode(String) Returns an HTML-encoded string that represents the specified string by using a full encoding that is suitable for arbitrary HTML.
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Public method Hidden(String) Returns an HTML hidden control that has the specified name.
Public method Hidden(String, Object) Returns an HTML hidden control that has the specified name and value.
Public method Hidden(String, Object, IDictionary<String, Object>) Returns an HTML hidden control that has the specified name, value, and custom attributes defined by an attribute dictionary.
Public method Hidden(String, Object, Object) Returns an HTML hidden control that has the specified name, value, and custom attributes defined by an attribute object.
Public method Label(String) Returns an HTML label that displays the specified text.
Public method Label(String, Object) Returns an HTML label that displays the specified text and that has the specified custom attributes.
Public method Label(String, String) Returns an HTML label that displays the specified text and that has the specified for attribute.
Public method Label(String, String, IDictionary<String, Object>) Returns an HTML label that displays the specified text, and that has the specified for attribute and custom attributes defined by an attribute dictionary.
Public method Label(String, String, Object) Returns an HTML label that displays the specified text, and that has the specified for attribute and custom attributes defined by an attribute object.
Public method ListBox(String, IEnumerable<SelectListItem>) Returns an HTML list box control that has the specified name and that contains the specified list items.
Public method ListBox(String, IEnumerable<SelectListItem>, IDictionary<String, Object>) Returns an HTML list box control that has the specified name and custom attributes defined by an attribute dictionary, and that contains the specified list items.
Public method ListBox(String, IEnumerable<SelectListItem>, Object) Returns an HTML list box control that has the specified name and custom attributes defined by an attribute object, and that contains the specified list items.
Public method ListBox(String, String, IEnumerable<SelectListItem>) Returns an HTML list box control that has the specified name, and that contains the specified list items and default item.
Public method ListBox(String, String, IEnumerable<SelectListItem>, IDictionary<String, Object>) Returns an HTML list box control that has the specified name and custom attributes defined by an attribute dictionary, and that contains the specified list items and default item.
Public method ListBox(String, String, IEnumerable<SelectListItem>, Object) Returns an HTML list box control that has the specified name and custom attributes defined by an attribute object, and that contains the specified list items and default item.
Public method ListBox(String, IEnumerable<SelectListItem>, Object, Int32, Boolean) Returns an HTML list box control that has the specified name, size, list items, and default selections, and that specifies whether multiple selections are enabled.
Public method ListBox(String, String, IEnumerable<SelectListItem>, Object, IDictionary<String, Object>) Returns an HTML list box control that has the specified name and custom attributes defined by an attribute dictionary, and that contains the specified list items, default item, and selections.
Public method ListBox(String, String, IEnumerable<SelectListItem>, Object, Object) Returns an HTML list box control that has the specified name, items, default item, and custom attributes defined by an attribute object, and selections.
Public method ListBox(String, String, IEnumerable<SelectListItem>, Object, Int32, Boolean) Returns an HTML list box control that has the specified name, size, items, default item, and selections, and that specifies whether multiple selections are enabled.
Public method ListBox(String, String, IEnumerable<SelectListItem>, Object, Int32, Boolean, IDictionary<String, Object>) Returns an HTML list box control that has the specified name, size, custom attributes defined by an attribute dictionary, items, default item, and selections, and that specifies whether multiple selections are enabled.
Public method ListBox(String, String, IEnumerable<SelectListItem>, Object, Int32, Boolean, Object) Returns an HTML list box control that has the specified name, size, custom attributes defined by an attribute object, items, default item, and selections, and that specifies whether multiple selections are enabled.
Protected method MemberwiseClone (Inherited from Object.)
Public methodStatic member ObjectToDictionary Creates a dictionary from an object, by adding each public instance property as a key with its associated value to the dictionary. It will expose public properties from derived types as well. This is typically used with objects of an anonymous type.
Public method Password(String) Returns an HTML password control that has the specified name.
Public method Password(String, Object) Returns an HTML password control that has the specified name and value.
Public method Password(String, Object, IDictionary<String, Object>) Returns an HTML password control that has the specified name, value, and custom attributes defined by an attribute dictionary.
Public method Password(String, Object, Object) Returns an HTML password control that has the specified name, value, and custom attributes defined by an attribute object.
Public method RadioButton(String, Object) Returns an HTML radio button control that has the specified name and value.
Public method RadioButton(String, Object, Boolean) Returns an HTML radio button control that has the specified name, value, and default selected status.
Public method RadioButton(String, Object, IDictionary<String, Object>) Returns an HTML radio button control that has the specified name, value, and custom attributes defined by an attribute dictionary.
Public method RadioButton(String, Object, Object) Returns an HTML radio button control that has the specified name, value, and custom attributes defined by an attribute object.
Public method RadioButton(String, Object, Boolean, IDictionary<String, Object>) Returns an HTML radio button control that has the specified name, value, default selected status, and custom attributes defined by an attribute dictionary.
Public method RadioButton(String, Object, Boolean, Object) Returns an HTML radio button control that has the specified name, value, default selected status, and custom attributes defined by an attribute object.
Public method Raw(Object) Wraps HTML markup in an HtmlString instance so that it is interpreted as HTML markup.
Public method Raw(String) Wraps HTML markup in an HtmlString instance so that it is interpreted as HTML markup.
Public method TextArea(String) Returns an HTML multi-line text input (text area) control that has the specified name.
Public method TextArea(String, IDictionary<String, Object>) Returns an HTML multi-line text input (text area) control that has the specified name and custom attributes defined by an attribute dictionary.
Public method TextArea(String, Object) Returns an HTML multi-line text input (text area) control that has the specified name and custom attributes defined by an attribute object.
Public method TextArea(String, String) Returns an HTML multi-line text input (text area) control that has the specified name and value.
Public method TextArea(String, String, IDictionary<String, Object>) Returns an HTML multi-line text input (text area) control that has the specified name, value, and custom attributes defined by an attribute dictionary.
Public method TextArea(String, String, Object) Returns an HTML multi-line text input (text area) control that has the specified name, value, and custom attributes defined by an attribute object.
Public method TextArea(String, String, Int32, Int32, IDictionary<String, Object>) Returns an HTML multi-line text input (text area) control that has the specified name, value, row attribute, col attribute, and custom attributes defined by an attribute dictionary.
Public method TextArea(String, String, Int32, Int32, Object) Returns an HTML multi-line text input (text area) control that has the specified name, value, row attribute, col attribute, and custom attributes defined by an attribute object.
Public method TextBox(String) Returns an HTML text control that has the specified name.
Public method TextBox(String, Object) Returns an HTML text control that has the specified name and value.
Public method TextBox(String, Object, IDictionary<String, Object>) Returns an HTML text control that has the specified name, value, and custom attributes defined by an attribute dictionary.
Public method TextBox(String, Object, Object) Returns an HTML text control that has the specified name, value, and custom attributes defined by an attribute object.
Public method ToString (Inherited from Object.)
Public method ValidationMessage(String) Returns an HTML span element that contains the first validation error message for the specified form field.
Public method ValidationMessage(String, IDictionary<String, Object>) Returns an HTML span element that has the specified custom attributes defined by an attribute dictionary, and that contains the first validation error message for the specified form field.
Public method ValidationMessage(String, Object) Returns an HTML span element that has the specified custom attributes defined by an attribute object, and that contains the first validation error message for the specified form field.
Public method ValidationMessage(String, String) Returns an HTML span element that contains a validation error message for the specified form field.
Public method ValidationMessage(String, String, IDictionary<String, Object>) Returns an HTML span element that has the specified custom attributes defined by an attribute dictionary, and that contains a validation error message for the specified form field.
Public method ValidationMessage(String, String, Object) Returns an HTML span element that has the specified custom attributes defined by an attribute object, and that contains a validation error message for the specified form field.
Public method ValidationSummary() Returns an HTML div element that contains an unordered list of all validation error messages from the model-state dictionary.
Public method ValidationSummary(Boolean) Returns an HTML div element that contains an unordered list of validation error message from the model-state dictionary, optionally excluding field-level errors.
Public method ValidationSummary(IDictionary<String, Object>) Returns an HTML div element that has the specified custom attributes defined by an attribute dictionary, and that contains an unordered list of all validation error messages that are in the model-state dictionary.
Public method ValidationSummary(Object) Returns an HTML div element that has the specified custom attributes defined by an attribute object, and that contains an unordered list of all validation error messages that are in the model-state dictionary.
Public method ValidationSummary(String) Returns an HTML div element that contains a summary message and an unordered list of all validation error messages that are in the model-state dictionary.
Public method ValidationSummary(String, IDictionary<String, Object>) Returns an HTML div element that has the specified custom attributes defined by an attribute dictionary, and that contains a summary message and an unordered list of all validation error message from the model-state dictionary.
Public method ValidationSummary(String, Object) Returns an HTML div element that has the specified custom attributes defined by an attribute object, and that contains a summary message and an unordered list of all validation error message from the model-state dictionary.
Public method ValidationSummary(String, Boolean, IDictionary<String, Object>) Returns an HTML div element that has the specified custom attributes defined by an attribute dictionary, and that contains a summary message and an unordered list of validation error message from the model-state dictionary, optionally excluding field-level errors.
Public method ValidationSummary(String, Boolean, Object) Returns an HTML div element that has the specified custom attributes defined by an attribute object, and that contains a summary message and an unordered list of validation error message from the model-state dictionary, optionally excluding field-level errors.

Top

Remarks

The HtmlHelper class lets you render HTML form elements, perform validation, and display validation messages for those elements. To render an HTML form element in the body of a web page, you call the method for that element and pass a value for its name attribute. For example, to create an input element that renders a text box, you can use @Html.TextBox("CustomerID"). This adds markup to the rendered page that resembles the following example:

<input id="CustomerID" name="CustomerID" type="text" value="" />

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Web.WebPages.Html Namespace