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

AddClass() public method

public AddClass ( string className ) : void
className string
return void
        public void AddClass(string className)
        {
            string old;
            if (Attributes.TryGetValue("class", out old) && old!=null)
            {
                Attributes["class"] = old + " " + className;
            }
            else
            {
                Attributes["class"] = className;
            }
        }

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::AddClass