private static BootstrapAlert BeginAlertHelper(this HtmlHelper html, string alertClassName, string title, string id, string className) { TagBuilder tag = new TagBuilder("div"); tag.AddOrMergeAttribute("class", "alert"); if (!String.IsNullOrEmpty(alertClassName)) tag.AddOrMergeAttribute("class", alertClassName); if (!String.IsNullOrEmpty(className)) tag.AddOrMergeAttribute("class", className); if (!String.IsNullOrEmpty(id)) tag.Attributes.Add("id", id); html.ViewContext.Writer.Write(tag.ToString(TagRenderMode.StartTag)); if (!String.IsNullOrEmpty(title)) { TagBuilder titleTag = new TagBuilder("h4"); titleTag.MergeAttribute("class", "alert-heading"); titleTag.SetInnerText(title); html.ViewContext.Writer.Write(titleTag.ToString(TagRenderMode.Normal)); } BootstrapAlert theAlert = new BootstrapAlert(html.ViewContext); return theAlert; }
internal DropDownBuilder(HtmlHelper <TModel> htmlHelper, DropDown dropDown, string wrapperTag = null, object wrapperTagHtmlAttributes = null) : base(htmlHelper, dropDown) { this.wrapperTag = wrapperTag; string beginWrapperTag = string.Empty; if (!string.IsNullOrEmpty(this.wrapperTag)) { TagBuilder wrapperTagBuilder = new TagBuilder(this.wrapperTag); wrapperTagBuilder.MergeAttributes(wrapperTagHtmlAttributes.ObjectToHtmlAttributesDictionary()); beginWrapperTag = wrapperTagBuilder.ToString(TagRenderMode.StartTag); } TagBuilder trigger = new TagBuilder("a"); trigger.AddOrMergeAttribute("data-toggle", "dropdown"); trigger.AddOrMergeAttribute("href", "#"); if (this.wrapperTag != "li") { trigger.AddCssClass("btn dropdown-toggle"); } trigger.InnerHtml = base.element._actionText + (this.wrapperTag != "li" ? @" <span class=""caret""></span>" : string.Empty); if (!string.IsNullOrEmpty(this.wrapperTag)) { base.textWriter.Write(beginWrapperTag); } base.textWriter.Write(trigger.ToString(TagRenderMode.Normal)); base.textWriter.Write(@"<ul class=""dropdown-menu"">"); }
public virtual string ToHtmlString() { var input = new TagBuilder("button"); input.Attributes.Add("type", _model.type); if (!string.IsNullOrEmpty(_model.name)) { input.Attributes.Add("name", _model.name); } if (!string.IsNullOrEmpty(_model.id)) { input.Attributes.Add("id", _model.id); } if (!string.IsNullOrEmpty(_model.value)) { input.Attributes.Add("value", _model.value); } input.MergeAttributes(_model.htmlAttributes.FormatHtmlAttributes()); input.AddCssClass(BootstrapHelper.GetClassForButtonSize(_model.size)); input.AddCssClass(BootstrapHelper.GetClassForButtonStyle(_model.style)); if (_model.buttonBlock) { input.AddCssClass("btn-block"); } if (_model.isDropDownToggle) { input.AddCssClass("dropdown-toggle"); input.AddOrMergeAttribute("data-toggle", "dropdown"); } if (_model.disabled) { input.AddCssClass("disabled"); input.AddOrMergeAttribute("disabled", ""); } if (!string.IsNullOrEmpty(_model.loadingText)) { input.AddOrMergeAttribute("data-loading-text", _model.loadingText); } input.AddCssClass("btn"); if (_withCaret) { if (!string.IsNullOrEmpty(_model.text)) { _model.text += " "; } _model.text += "<span class='caret'></span>"; } if (_model.iconPrepend != Icons._not_set || _model.iconAppend != Icons._not_set || !string.IsNullOrEmpty(_model.iconPrependCustomClass) || !string.IsNullOrEmpty(_model.iconAppendCustomClass)) { var iPrependString = string.Empty; var iAppendString = string.Empty; if (_model.iconPrepend != Icons._not_set) { iPrependString = new BootstrapIcon(_model.iconPrepend, _model.iconPrependIsWhite).ToHtmlString(); } if (_model.iconAppend != Icons._not_set) { iAppendString = new BootstrapIcon(_model.iconAppend, _model.iconAppendIsWhite).ToHtmlString(); } if (!string.IsNullOrEmpty(_model.iconPrependCustomClass)) { var i = new TagBuilder("i"); i.AddCssClass(_model.iconPrependCustomClass); iPrependString = i.ToString(TagRenderMode.Normal); } if (!string.IsNullOrEmpty(_model.iconAppendCustomClass)) { var i = new TagBuilder("i"); i.AddCssClass(_model.iconAppendCustomClass); iAppendString = i.ToString(TagRenderMode.Normal); } _model.text = iPrependString + (!string.IsNullOrEmpty(iPrependString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iAppendString)) ? " " : "") + _model.text + (!string.IsNullOrEmpty(iAppendString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iPrependString)) ? " " : "") + iAppendString; } input.InnerHtml = _model.text; return(input.ToString()); }
public virtual string ToHtmlString() { var input = new TagBuilder("button"); input.Attributes.Add("type", _model.type); if (!string.IsNullOrEmpty(_model.name)) { input.Attributes.Add("name", _model.name); } if (!string.IsNullOrEmpty(_model.id)) { input.Attributes.Add("id", _model.id); } if (!string.IsNullOrEmpty(_model.value)) { input.Attributes.Add("value", _model.value); } if (_model.tooltip != null) { _model.htmlAttributes.MergeHtmlAttributes(_model.tooltip.ToDictionary()); } if (_model.popover != null) { _model.htmlAttributes.MergeHtmlAttributes(_model.popover.ToDictionary()); } input.MergeAttributes(_model.htmlAttributes.FormatHtmlAttributes()); input.AddCssClass(BootstrapHelper.GetClassForButtonSize(_model.size)); input.AddCssClass(BootstrapHelper.GetClassForButtonColor(_model.color)); if (_model.buttonBlock) { input.AddCssClass("btn-block"); } if (_model.isShiny) { input.AddCssClass("shiny"); } if (_model.circular) { input.AddCssClass("btn-circle"); } if (_model.iconOnly) { input.AddCssClass("icon-only"); } if (_model.labeled) { input.AddCssClass("btn-labeled"); } if (_model.isDropDownToggle) { input.AddCssClass("dropdown-toggle"); input.AddOrMergeAttribute("data-toggle", "dropdown"); } if (_model.disabled) { input.AddCssClass("disabled"); input.AddOrMergeAttribute("disabled", ""); } if (!string.IsNullOrEmpty(_model.loadingText)) { input.AddOrMergeAttribute("data-loading-text", _model.loadingText); } input.AddCssClass("btn"); if (_withCaret) { if (!string.IsNullOrEmpty(_model.text)) { _model.text += " "; } _model.text += "<span class='caret'></span>"; } if (_model.iconPrepend != String.Empty || _model.iconAppend != String.Empty || !string.IsNullOrEmpty(_model.iconPrependCustomClass) || !string.IsNullOrEmpty(_model.iconAppendCustomClass)) { var iPrependString = string.Empty; var iAppendString = string.Empty; var iconLabelString = ""; if (_model.labeled) { iconLabelString = " btn-label"; } if (_model.iconPrepend != String.Empty) { iPrependString = new BootstrapIcon(_model.iconPrepend + iconLabelString, _model.iconPrependIsWhite).ToHtmlString(); } if (_model.iconAppend != String.Empty) { iAppendString = new BootstrapIcon(_model.iconAppend + " right" + iconLabelString, _model.iconAppendIsWhite).ToHtmlString(); } if (!string.IsNullOrEmpty(_model.iconPrependCustomClass)) { var i = new TagBuilder("i"); i.AddCssClass(_model.iconPrependCustomClass); iPrependString = i.ToString(TagRenderMode.Normal); } if (!string.IsNullOrEmpty(_model.iconAppendCustomClass)) { var i = new TagBuilder("i"); i.AddCssClass(_model.iconAppendCustomClass); iAppendString = i.ToString(TagRenderMode.Normal); } _model.text = iPrependString + (!string.IsNullOrEmpty(iPrependString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iAppendString)) ? " " : "") + _model.text + (!string.IsNullOrEmpty(iAppendString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iPrependString)) ? " " : "") + iAppendString; } input.InnerHtml = _model.text; return(input.ToString()); }