Class HtmlAttributes
Represents a set of HTML attributes.
Implements
Inherited Members
Namespace: ChameleonForms
Assembly: ChameleonForms.Core.dll
Syntax
public class HtmlAttributes : IHtmlContent
Constructors
| Improve this Doc View SourceHtmlAttributes(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", ""rubbi&h""}});
| Improve this Doc View SourceHtmlAttributes(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", ""rubbi&h""}});
| Improve this Doc View SourceHtmlAttributes(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 => ""rubbi&h"");
| Improve this Doc View SourceHtmlAttributes(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 = ""rubbi&h"" });
Properties
| Improve this Doc View SourceAttributes
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 SourceAddClass(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 |
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 SourceAttr(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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 SourceImplicit(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 |
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 |