TagBuilder Class

Contains classes and properties that are used to create HTML elements. This class is used to write helpers, such as those found in the System.Web.Helpers namespace.

Inheritance Hierarchy


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


Public Class TagBuilder
Dim instance As TagBuilder
public class TagBuilder
public ref class TagBuilder
type TagBuilder =  class end
public class TagBuilder

The TagBuilder type exposes the following members.


  Name Description
Public method TagBuilder Creates a new tag that has the specified tag name.



  Name Description
Public property Attributes Gets the collection of attributes.
Public property IdAttributeDotReplacement Gets or sets a string that can be used to replace invalid HTML characters.
Public property InnerHtml Gets or sets the inner HTML value for the element.
Public property TagName Gets the tag name for this tag.



  Name Description
Public method AddCssClass Adds a CSS class to the list of CSS classes in the tag.
Public methodStatic member CreateSanitizedId(String) Replaces each invalid character in the tag ID with a valid HTML character.
Public methodStatic member CreateSanitizedId(String, String) Replaces each invalid character in the tag ID with the specified replacement string.
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GenerateId Generates a sanitized ID attribute for the tag by using the specified name.
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Public method MergeAttribute(String, String) Adds a new attribute to the tag.
Public method MergeAttribute(String, String, Boolean) Adds a new attribute or optionally replaces an existing attribute in the opening tag.
Public method MergeAttributes<TKey, TValue>(IDictionary<TKey, TValue>) Adds new attributes to the tag.
Public method MergeAttributes<TKey, TValue>(IDictionary<TKey, TValue>, Boolean) Adds new attributes or optionally replaces existing attributes in the tag.
Public method SetInnerText Sets the InnerHtml property of the element to an HTML-encoded version of the specified string.
Public method ToString() Renders the element as a Normal element. (Overrides Object.ToString().)
Public method ToString(TagRenderMode) Renders the HTML tag by using the specified render mode.


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


System.Web.Mvc Namespace