/// <summary> /// Create an Image with innerHtml, buttonType, htmlAttributes. /// </summary> /// <param name="htmlHelper"></param> /// <param name="innerHtml">Display name</param> /// <param name="buttonType">Button type</param> /// <param name="htmlAttributes">Html Attributes</param> /// <returns></returns> public static MvcHtmlString Button(this HtmlHelper htmlHelper, string innerHtml, HtmlButtonTypes buttonType = null, object htmlAttributes = null ) { return(ButtonHtmlExtention.Button(htmlHelper, innerHtml, string.Empty, string.Empty, string.Empty, buttonType, htmlAttributes)); }
/// <summary> /// Create an Image with innerHtml, cssClasses, name, glyphicon, buttonType, htmlAttributes. /// </summary> /// <param name="htmlHelper"></param> /// <param name="innerHtml">Display name</param> /// <param name="cssClass">Class for CSS</param> /// <param name="name">Name and Id</param> /// <param name="glyphicon">Glyphicon Boostrap Class</param> /// <param name="buttonType">Button type</param> /// <param name="htmlAttributes">Html Attributes</param> /// <returns></returns> public static MvcHtmlString Button(this HtmlHelper htmlHelper, string innerHtml, string cssClass, string glyphicon, string name, HtmlButtonTypes buttonType = null, object htmlAttributes = null ) { TagBuilder tb = new TagBuilder("button"); if (!string.IsNullOrWhiteSpace(cssClass)) { if (!cssClass.Contains("btn-")) { cssClass = "btn-primary " + cssClass; } } else { cssClass = "btn-primary"; } cssClass = "btn " + cssClass; tb.AddCssClass(cssClass); HtmlExtentionsCommon.AddName(tb, name); tb.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes)); if (!string.IsNullOrWhiteSpace(glyphicon)) { TagBuilder span = new TagBuilder("span"); span.AddCssClass(glyphicon); span.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(new { aria_hidden = "true" })); span.InnerHtml = " " + innerHtml; tb.InnerHtml = span.ToString() + " "; } else { tb.InnerHtml += innerHtml; } if (buttonType == null || string.IsNullOrWhiteSpace(buttonType.Value)) { buttonType = HtmlButtonTypes.Submit; } tb.MergeAttribute("type", buttonType.Value); return(MvcHtmlString.Create(tb.ToString())); }