Show / Hide Table of Contents

    Class HtmlAttributes

    Represents a set of HTML attributes.

    Inheritance
    System.Object
    HtmlAttributes
    LazyHtmlAttributes
    Implements
    Microsoft.AspNetCore.Html.IHtmlContent
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: ChameleonForms
    Assembly: ChameleonForms.Core.dll
    Syntax
    public class HtmlAttributes : IHtmlContent

    Constructors

    | Improve this Doc View Source

    HtmlAttributes(IDictionary<String, Object>)

    Constructs a HtmlAttributes object using a dictionary to express the attributes.

    Declaration
    public HtmlAttributes(IDictionary<string, object> attributes)
    Parameters
    Type Name Description
    System.Collections.Generic.IDictionary<System.String, System.Object> attributes

    A dictionary of attributes

    Examples

    var h = new HtmlAttributes(new Dictionary<string, object> {{"style", "width: 100%;"}, {"cellpadding", 0}, {"class", "class1 class2"}, {"src", "http://url/"}, {"data-somedata", "&quot;rubbi&h&quot;"}});

    | Improve this Doc View Source

    HtmlAttributes(IDictionary<String, String>)

    Constructs a HtmlAttributes object using a dictionary to express the attributes.

    Declaration
    public HtmlAttributes(IDictionary<string, string> attributes)
    Parameters
    Type Name Description
    System.Collections.Generic.IDictionary<System.String, System.String> attributes

    A dictionary of attributes

    Examples

    var h = new HtmlAttributes(new Dictionary<string, string> {{"style", "width: 100%;"}, {"cellpadding", "0"}, {"class", "class1 class2"}, {"src", "http://url/"}, {"data-somedata", "&quot;rubbi&h&quot;"}});

    | Improve this Doc View Source

    HtmlAttributes(Func<Object, Object>[])

    Constructs a HtmlAttributes object using lambda methods to express the attributes.

    Declaration
    public HtmlAttributes(params Func<object, object>[] attributes)
    Parameters
    Type Name Description
    System.Func<System.Object, System.Object>[] attributes

    A list of lambas where the lambda variable name is the name of the attribute and the value is the value

    Examples

    var h = new HtmlAttributes(style => "width: 100%;", cellpadding => 0, @class => "class1 class2", src => "http://url/", data_somedata => "&quot;rubbi&h&quot;");

    | Improve this Doc View Source

    HtmlAttributes(Object)

    Constructs a HtmlAttributes object using an anonymous object to express the attributes.

    Declaration
    public HtmlAttributes(object attributes)
    Parameters
    Type Name Description
    System.Object attributes

    An anonymous object of attributes

    Examples

    var h = new HtmlAttributes(new { style = "width: 100%;", cellpadding = 0, @class = "class1 class2", src = "http://url/", data_somedata = "&quot;rubbi&h&quot;" });

    Properties

    | Improve this Doc View Source

    Attributes

    Dictionary of the attributes currently stored in the object.

    Declaration
    public IDictionary<string, string> Attributes { get; }
    Property Value
    Type Description
    System.Collections.Generic.IDictionary<System.String, System.String>

    Methods

    | Improve this Doc View Source

    AddClass(String)

    Adds a CSS class (or a number of CSS classes) to the attributes.

    Declaration
    public HtmlAttributes AddClass(string class)
    Parameters
    Type Name Description
    System.String class

    The CSS class(es) to add

    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Attr(Func<Object, Object>)

    Adds or updates a HTML attribute with using a lambda method to express the attribute.

    Declaration
    public HtmlAttributes Attr(Func<object, object> attribute)
    Parameters
    Type Name Description
    System.Func<System.Object, System.Object> attribute

    A lambda expression representing the attribute to set and its value

    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    Examples

    h.Attr(style => "width: 100%;")

    | Improve this Doc View Source

    Attr(String, Object)

    Adds or updates a HTML attribute with a given value.

    Declaration
    public HtmlAttributes Attr(string key, object value)
    Parameters
    Type Name Description
    System.String key

    The name of the HTML attribute to add/update

    System.Object value

    The value of the HTML attribute to add/update

    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Attrs(IDictionary<String, Object>)

    Adds or updates a set of HTML attributes using a dictionary to express the attributes.

    Declaration
    public HtmlAttributes Attrs(IDictionary<string, object> attributes)
    Parameters
    Type Name Description
    System.Collections.Generic.IDictionary<System.String, System.Object> attributes

    A dictionary of attributes

    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Attrs(IDictionary<String, String>)

    Adds or updates a set of HTML attributes using a dictionary to express the attributes.

    Declaration
    public HtmlAttributes Attrs(IDictionary<string, string> attributes)
    Parameters
    Type Name Description
    System.Collections.Generic.IDictionary<System.String, System.String> attributes

    A dictionary of attributes

    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Attrs(Func<Object, Object>[])

    Adds or updates a set of HTML attributes using lambda methods to express the attributes.

    Declaration
    public HtmlAttributes Attrs(params Func<object, object>[] attributes)
    Parameters
    Type Name Description
    System.Func<System.Object, System.Object>[] attributes

    A list of lambas where the lambda variable name is the name of the attribute and the value is the value

    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Attrs(Object)

    Adds or updates a set of HTML attributes using anonymous objects to express the attributes.

    Declaration
    public HtmlAttributes Attrs(object attributes)
    Parameters
    Type Name Description
    System.Object attributes

    An anonymous object of attributes

    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Disabled(Boolean)

    Sets the disabled attribute.

    Declaration
    public HtmlAttributes Disabled(bool disabled = true)
    Parameters
    Type Name Description
    System.Boolean disabled
    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Has(String)

    Returns whether or not a value is set for the given attribute.

    Declaration
    public bool Has(string key)
    Parameters
    Type Name Description
    System.String key

    The name of the HTML attribute to check

    Returns
    Type Description
    System.Boolean

    Whether or not there is a value set for the attribute

    | Improve this Doc View Source

    Id(String)

    Set the id attribute.

    Declaration
    public HtmlAttributes Id(string id)
    Parameters
    Type Name Description
    System.String id

    The text to use for the id

    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Readonly(Boolean)

    Sets the readonly attribute.

    Declaration
    public HtmlAttributes Readonly(bool readonly = true)
    Parameters
    Type Name Description
    System.Boolean readonly
    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    Required(Boolean)

    Sets the required attribute.

    Declaration
    public HtmlAttributes Required(bool required = true)
    Parameters
    Type Name Description
    System.Boolean required
    Returns
    Type Description
    HtmlAttributes

    The HtmlAttributes attribute to allow for method chaining

    | Improve this Doc View Source

    ToDictionary()

    Returns the HTML attributes as a dictionary.

    Declaration
    public IDictionary<string, object> ToDictionary()
    Returns
    Type Description
    System.Collections.Generic.IDictionary<System.String, System.Object>

    A dictionary of HTML attributes compatible with the standard ASP.NET MVC method signatures

    | Improve this Doc View Source

    WriteTo(TextWriter, HtmlEncoder)

    Called when form component outputted to the page; writes the form content HTML to the given writer.

    Declaration
    public virtual void WriteTo(TextWriter writer, HtmlEncoder encoder)
    Parameters
    Type Name Description
    System.IO.TextWriter writer

    The writer to write to

    System.Text.Encodings.Web.HtmlEncoder encoder

    The HTML encoder to use when writing

    Operators

    | Improve this Doc View Source

    Implicit(Dictionary<String, Object> to HtmlAttributes)

    Implicitly convert from a dictionary to a new HtmlAttributes object.

    Declaration
    public static implicit operator HtmlAttributes(Dictionary<string, object> attributes)
    Parameters
    Type Name Description
    System.Collections.Generic.Dictionary<System.String, System.Object> attributes

    The dictionary of HTML attributes

    Returns
    Type Description
    HtmlAttributes

    The new HtmlAttributes object

    | Improve this Doc View Source

    Implicit(Dictionary<String, String> to HtmlAttributes)

    Implicitly convert from a dictionary to a new HtmlAttributes object.

    Declaration
    public static implicit operator HtmlAttributes(Dictionary<string, string> attributes)
    Parameters
    Type Name Description
    System.Collections.Generic.Dictionary<System.String, System.String> attributes

    The dictionary of HTML attributes

    Returns
    Type Description
    HtmlAttributes

    The new HtmlAttributes object

    Implements

    Microsoft.AspNetCore.Html.IHtmlContent

    Extension Methods

    HtmlAttributesExtensions.ToHtmlAttributes(Object)
    HtmlContentExtensions.ToHtmlString(IHtmlContent)
    • Improve this Doc
    • View Source
    Back to top © Copyright 2012-2020 MRCollective, Rob Moore, Matt Davies and the contributors to ChameleonForms.