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

            HtmlExtensionsCommon.AddName(tb, name, "");

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

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

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

            // HTML Encode the String
            return(MvcHtmlString.Create(
                       tb.ToString(TagRenderMode.SelfClosing)));
        }
Esempio n. 2
0
        public static MvcHtmlString BootstrapButton(
            this HtmlHelper htmlHelper,
            string innerHtml,
            string cssClass,
            string name,
            string title,
            bool isFormNoValidate,
            bool isAutoFocus,
            HtmlExtensionsCommon.HtmlButtonTypes buttonType,
            string pdsaAction,
            object htmlAttributes = null)
        {
            TagBuilder tb = new TagBuilder("button");

            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                if (!cssClass.Contains("btn-"))
                {
                    cssClass = "btn-primary " + cssClass;
                }
            }
            else
            {
                cssClass = "btn-primary";
            }

            tb.AddCssClass(cssClass);

            tb.AddCssClass("btn");

            if (!string.IsNullOrWhiteSpace(pdsaAction))
            {
                tb.MergeAttribute("data-pdsa-action", pdsaAction);
            }

            if (!string.IsNullOrWhiteSpace(title))
            {
                tb.MergeAttribute("title", title);
            }
            if (isFormNoValidate)
            {
                tb.MergeAttribute("formnovalidate", "formnovalidate");
            }
            if (isAutoFocus)
            {
                tb.MergeAttribute("autofocus", "autofocus");
            }

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

            HtmlExtensionsCommon.AddName(tb, name, "");

            tb.InnerHtml = innerHtml;

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

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

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


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