Exemple #1
0
        public static MvcHtmlString BootstrapTextBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                         Expression <Func <TModel, TValue> > bindingExpresion,
                                                                         string name, string placeHolder, string title, string cssClass, object htmlAttributes = null)
        {
            RouteValueDictionary rvd = new RouteValueDictionary(HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));

            if (!string.IsNullOrEmpty(name))
            {
                HtmlCommonProperty.AddIdName(rvd, name, null);
            }

            if (!string.IsNullOrEmpty(placeHolder))
            {
                rvd.Add("placeHolder", placeHolder);
            }

            if (!string.IsNullOrEmpty(title))
            {
                rvd.Add("title", title);
            }

            if (string.IsNullOrEmpty(cssClass))
            {
                cssClass = "form-control";
            }
            else
            {
                cssClass = "form-control " + cssClass;
            }

            rvd.Add("class", cssClass);


            return(InputExtensions.TextBoxFor(htmlHelper, bindingExpresion, rvd));
        }
Exemple #2
0
        public static MvcHtmlString BootstrapButton(this HtmlHelper htmlHelper, string innerHtml, string cssClass
                                                    , string name, HtmlCommonProperty.ButtonType buttonType, string title, object htmlAttributes = null)
        {
            TagBuilder tb = new TagBuilder("button");

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

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

            tb.InnerHtml = innerHtml;

            HtmlCommonProperty.AddIdName(tb, name, "");

            switch (buttonType)
            {
            case HtmlCommonProperty.ButtonType.button:
                tb.MergeAttribute("type", "button");
                break;

            case HtmlCommonProperty.ButtonType.submit:
                tb.MergeAttribute("type", "submit");
                break;

            case HtmlCommonProperty.ButtonType.reset:
                tb.MergeAttribute("type", "reset");
                break;
            }

            if (!string.IsNullOrEmpty(title))
            {
                tb.MergeAttribute("title", title);
            }

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

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