Manos.Mvc.TagBuilder.AddAttributes C# (CSharp) Method

AddAttributes() public method

public AddAttributes ( object attributes ) : void
attributes object
return void
        public void AddAttributes(object attributes)
        {
            if (attributes == null)
                return;

            foreach (var pi in attributes.GetType().GetProperties())
            {
                AddAttribute(pi.Name, pi.GetValue(attributes, null).ToString());
            }
        }

Usage Example

        public static HtmlString CheckBox(this HtmlHelper This, string key, object value = null, object htmlAttributes = null)
        {
            This.RegisterFormField(key);

            var tag = new TagBuilder("input");

            tag.AddAttribute("type", "checkbox");
            tag.AddAttribute("name", key);
            tag.AddAttribute("id", key);
            tag.AddAttribute("value", "true");
            tag.AddAttributes(htmlAttributes);

            if ((bool)Convert.ChangeType(This.ResolveFormValue(key, value), typeof(bool)))
            {
                tag.AddAttribute("checked", "checked");
            }

            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            return new HtmlString(tag.Render());
        }
All Usage Examples Of Manos.Mvc.TagBuilder::AddAttributes