Export (0) Print
Expand All

HtmlHelper Class

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

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

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

public class HtmlHelper

The HtmlHelper type exposes the following members.

  NameDescription
Public propertyStatic memberIdAttributeDotReplacementGets or sets the character that is used to replace the dot (.) in the id attribute of rendered form controls.
Public propertyStatic memberUnobtrusiveJavaScriptEnabledGets or sets a value that indicates whether the page uses unobtrusive JavaScript for Ajax functionality.
Public propertyStatic memberValidationInputCssClassNameGets or sets the name of the CSS class that defines the appearance of input elements when validation fails.
Public propertyStatic memberValidationInputValidCssClassNameGets or sets the name of the CSS class that defines the appearance of input elements when validation passes.
Public propertyStatic memberValidationMessageCssClassNameGets or sets the name of the CSS class that defines the appearance of validation error messages when validation fails.
Public propertyStatic memberValidationMessageValidCssClassNameGets or sets the name of the CSS class that defines the appearance of validation error messages when validation passes.
Public propertyStatic memberValidationSummaryClassGets or sets the name of the CSS class that defines the appearance of a validation summary when validation fails.
Public propertyStatic memberValidationSummaryValidClassGets or sets the name of the CSS class that defines the appearance of a validation summary when validation passes.
Top

  NameDescription
Public methodStatic memberAnonymousObjectToHtmlAttributesCreates a dictionary of HTML attributes from the input object, translating underscores to dashes.
Public methodAttributeEncode(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 methodAttributeEncode(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 methodCheckBox(String)Returns an HTML check box control that has the specified name.
Public methodCheckBox(String, Boolean)Returns an HTML check box control that has the specified name and default checked status.
Public methodCheckBox(String, IDictionary<String, Object>)Returns an HTML check box control that has the specified name and custom attributes defined by an attribute dictionary.
Public methodCheckBox(String, Object)Returns an HTML check box control that has the specified name and custom attributes defined by an attribute object.
Public methodCheckBox(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 methodCheckBox(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 methodDropDownList(String, IEnumerable<SelectListItem>)Returns an HTML drop-down list control that has the specified name and that contains the specified list items.
Public methodDropDownList(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 methodDropDownList(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 methodDropDownList(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 methodDropDownList(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 methodDropDownList(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 methodDropDownList(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 methodDropDownList(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 methodEncode(Object)Returns an HTML-encoded string that represents the specified object by using a full encoding that is suitable for arbitrary HTML.
Public methodEncode(String)Returns an HTML-encoded string that represents the specified string by using a full encoding that is suitable for arbitrary HTML.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodHidden(String)Returns an HTML hidden control that has the specified name.
Public methodHidden(String, Object)Returns an HTML hidden control that has the specified name and value.
Public methodHidden(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 methodHidden(String, Object, Object)Returns an HTML hidden control that has the specified name, value, and custom attributes defined by an attribute object.
Public methodLabel(String)Returns an HTML label that displays the specified text.
Public methodLabel(String, Object)Returns an HTML label that displays the specified text and that has the specified custom attributes.
Public methodLabel(String, String)Returns an HTML label that displays the specified text and that has the specified for attribute.
Public methodLabel(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 methodLabel(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 methodListBox(String, IEnumerable<SelectListItem>)Returns an HTML list box control that has the specified name and that contains the specified list items.
Public methodListBox(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 methodListBox(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 methodListBox(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 methodListBox(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 methodListBox(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 methodListBox(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 methodListBox(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 methodListBox(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 methodListBox(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 methodListBox(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 methodListBox(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 methodMemberwiseClone (Inherited from Object.)
Public methodStatic memberObjectToDictionaryCreates 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 methodPassword(String)Returns an HTML password control that has the specified name.
Public methodPassword(String, Object)Returns an HTML password control that has the specified name and value.
Public methodPassword(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 methodPassword(String, Object, Object)Returns an HTML password control that has the specified name, value, and custom attributes defined by an attribute object.
Public methodRadioButton(String, Object)Returns an HTML radio button control that has the specified name and value.
Public methodRadioButton(String, Object, Boolean)Returns an HTML radio button control that has the specified name, value, and default selected status.
Public methodRadioButton(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 methodRadioButton(String, Object, Object)Returns an HTML radio button control that has the specified name, value, and custom attributes defined by an attribute object.
Public methodRadioButton(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 methodRadioButton(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 methodRaw(Object)Wraps HTML markup in an HtmlString instance so that it is interpreted as HTML markup.
Public methodRaw(String)Wraps HTML markup in an HtmlString instance so that it is interpreted as HTML markup.
Public methodTextArea(String)Returns an HTML multi-line text input (text area) control that has the specified name.
Public methodTextArea(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 methodTextArea(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 methodTextArea(String, String)Returns an HTML multi-line text input (text area) control that has the specified name and value.
Public methodTextArea(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 methodTextArea(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 methodTextArea(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 methodTextArea(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 methodTextBox(String)Returns an HTML text control that has the specified name.
Public methodTextBox(String, Object)Returns an HTML text control that has the specified name and value.
Public methodTextBox(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 methodTextBox(String, Object, Object)Returns an HTML text control that has the specified name, value, and custom attributes defined by an attribute object.
Public methodToString (Inherited from Object.)
Public methodValidationMessage(String)Returns an HTML span element that contains the first validation error message for the specified form field.
Public methodValidationMessage(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 methodValidationMessage(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 methodValidationMessage(String, String)Returns an HTML span element that contains a validation error message for the specified form field.
Public methodValidationMessage(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 methodValidationMessage(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 methodValidationSummary()Returns an HTML div element that contains an unordered list of all validation error messages from the model-state dictionary.
Public methodValidationSummary(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 methodValidationSummary(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 methodValidationSummary(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 methodValidationSummary(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 methodValidationSummary(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 methodValidationSummary(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 methodValidationSummary(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 methodValidationSummary(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

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="" />

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