public static MvcHtmlString Render(BootStrapButtonType ButtonType, BootStrapButtonSize ButtonSize, BootStrapButtonTagType TagType, bool Block, bool Disabled, string InnerText, object HtmlAttributes, List<string> AdditionalClasses) { string stButtonType = GetButtonTypeClass(ButtonType); string stButtonSize = GetButtonSizeClass(ButtonSize); //Create tag string stTagName = GetTagName(TagType); TagBuilder tag = new TagBuilder(stTagName); //Attributes and classes are written from a stack (reverse order), so do them reverse order here //Add HTML attrbiutes if ((HtmlAttributes as Dictionary<string, string>) == null) { tag.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(HtmlAttributes), true); } else { tag.MergeAttributes((Dictionary<string, string>)HtmlAttributes, true); } if (AdditionalClasses != null) { //Add additional classes foreach (string C in AdditionalClasses) { tag.AddCssClass(C); } } //Add disabled class if necessary if (Disabled) { switch (TagType) { case BootStrapButtonTagType.INPUT_BUTTON: case BootStrapButtonTagType.INPUT_SUBMIT: case BootStrapButtonTagType.ANCHOR: tag.AddCssClass("disabled"); break; case BootStrapButtonTagType.BUTTON: tag.MergeAttribute("disabled", "disabled"); tag.AddCssClass("disabled"); break; } } //Add block class if necessary if (Block) { tag.AddCssClass("btn-block"); } //Add button size class tag.AddCssClass(stButtonSize); //Add button type class tag.AddCssClass(stButtonType); //Add base btn class tag.AddCssClass("btn"); if (TagType == BootStrapButtonTagType.BUTTON || TagType == BootStrapButtonTagType.INPUT_BUTTON) { //Add button type attribute tag.MergeAttribute("type", "button"); } else if (TagType == BootStrapButtonTagType.INPUT_SUBMIT) { tag.MergeAttribute("type", "submit"); } if (TagType == BootStrapButtonTagType.BUTTON || TagType == BootStrapButtonTagType.ANCHOR) { //Set inner text tag.InnerHtml = InnerText; } else { tag.MergeAttribute("value", InnerText); } TagRenderMode renderMode = TagRenderMode.Normal; if (TagType == BootStrapButtonTagType.INPUT_BUTTON || TagType == BootStrapButtonTagType.INPUT_SUBMIT) { renderMode = TagRenderMode.SelfClosing; } return new MvcHtmlString(tag.ToString(renderMode)); }
private static string GetButtonTypeClass(BootStrapButtonType ButtonType) { string stButtonType = string.Format("btn-{0}", ButtonType.ToString().ToLower()); return stButtonType; }
public MvcHtmlString Button(BootStrapButtonType ButtonType, BootStrapButtonSize ButtonSize, BootStrapButtonTagType TagType, bool Block, bool Disabled, string InnerText, object HtmlAttributes, List<string> AdditionalClasses) { return BootStrapButton.Render(ButtonType, ButtonSize, TagType, Block, Disabled, InnerText, HtmlAttributes, AdditionalClasses); }
public MvcHtmlString Button(BootStrapButtonType ButtonType, BootStrapButtonSize ButtonSize, BootStrapButtonTagType TagType, string InnerText, object HtmlAttributes) { return Button(ButtonType, ButtonSize, TagType, false, false, InnerText, HtmlAttributes, null); }
public MvcHtmlString Button(BootStrapButtonType ButtonType, BootStrapButtonSize ButtonSize, BootStrapButtonTagType TagType, string InnerText) { return Button(ButtonType, ButtonSize, TagType, false, false, InnerText, (object)null, null); }
public MvcHtmlString Button(BootStrapButtonType ButtonType, string InnerText) { return Button(ButtonType, BootStrapButtonSize.DEFAULT, BootStrapButtonTagType.BUTTON, false, false, InnerText, (object)null, null); }