Esempio n. 1
0
        public static MvcHtmlString BoostrapButton(this HtmlHelper htmlHelper,
                                                   string innerHtml,
                                                   string cssClass,
                                                   string name,
                                                   string id,
                                                   HtmlExtensionsCommon.HtmlButtonTypes buttonType = HtmlExtensionsCommon.HtmlButtonTypes.submit,
                                                   object htmlAttributes = null)
        {
            TagBuilder tb = new TagBuilder("button");

            if (string.IsNullOrWhiteSpace(cssClass))
            {
                cssClass = "btn-primary";
            }

            tb.AddCssClass(cssClass);
            tb.AddCssClass("btn");

            HtmlExtensionsCommon.AddName(tb, name, id);

            tb.InnerHtml = innerHtml;

            switch (buttonType)
            {
            case HtmlExtensionsCommon.HtmlButtonTypes.submit:
                tb.MergeAttribute("type", "submit");
                break;

            case HtmlExtensionsCommon.HtmlButtonTypes.reset:
                tb.MergeAttribute("type", "reset");
                break;

            case HtmlExtensionsCommon.HtmlButtonTypes.button:
                tb.MergeAttribute("type", "button");
                break;
            }


            return(MvcHtmlString.Create(tb.ToString()));
        }
Esempio n. 2
0
        public static MvcHtmlString Image(this HtmlHelper htmlHelper,
                                          string src,
                                          string altText,
                                          string cssClass,
                                          string name,
                                          object htmlAttributes = null)
        {
            TagBuilder tb = new TagBuilder("img");

            tb.MergeAttribute("src", src);
            tb.MergeAttribute("alt", altText);

            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                tb.AddCssClass(cssClass);
            }

            HtmlExtensionsCommon.AddName(tb, name, name);

            tb.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));

            return(MvcHtmlString.Create(tb.ToString(TagRenderMode.SelfClosing)));
        }