Esempio n. 1
0
        private static string GetDisplayText(IEnumerable<SelectListItem> selectList)
        {
            var stringBuilder = new StringBuilder();

            foreach (SelectListItem selectListItem in selectList.Where(x => x.Selected))
            {
                var builder = new HtmlTagBuilder("p");
                builder.AddClass("form-control-static");
                builder.InternalBuilder.SetInnerText(selectListItem.Text);
                stringBuilder.Append(builder.ToHtmlString());
            }

            return stringBuilder.ToString();
        }
Esempio n. 2
0
        public static IHtmlString Render(HtmlHelper html, ITextBoxBuilder textBoxBuilder, FormGroupDisplay display, Func<object> valueFactory, Func<MvcHtmlString> hiddenField)
        {
            bool readOnlyMode = display == FormGroupDisplay.ReadOnly, labelWithHiddenFieldMode = display == FormGroupDisplay.LabelWithHiddenField;

            if (readOnlyMode || labelWithHiddenFieldMode)
            {
                var value = valueFactory();

                var builder = new HtmlTagBuilder("p");
                builder.Attr(textBoxBuilder.HtmlAttributes);
                builder.AddClass("form-control-static");
                builder.InternalBuilder.SetInnerText(html.FormatValue(value, textBoxBuilder.Format()));

                if (labelWithHiddenFieldMode)
                {
                    builder.InternalBuilder.InnerHtml += hiddenField();
                }

                return builder;
            }

            return textBoxBuilder.AddClass("form-control");
        }
Esempio n. 3
0
        public static IHtmlString Render(HtmlHelper html, ISelectListBuilder selectListBuilder, FormGroupDisplay display, string expressionText, Func<MvcHtmlString> hiddenField)
        {
            bool readOnlyMode = display == FormGroupDisplay.ReadOnly, labelWithHiddenFieldMode = display == FormGroupDisplay.LabelWithHiddenField;

            if (readOnlyMode || labelWithHiddenFieldMode)
            {
                var builder = new HtmlTagBuilder("div");

                builder.Attr(selectListBuilder.HtmlAttributes);

                IEnumerable<SelectListItem> selectList = SelectListHelper.GetSelectListItems(html, selectListBuilder, expressionText);

                builder.InternalBuilder.InnerHtml = GetDisplayText(selectList);

                if (labelWithHiddenFieldMode)
                {
                    builder.InternalBuilder.InnerHtml += hiddenField();
                }

                return MvcHtmlString.Create(builder.ToHtmlString());
            }

            return selectListBuilder.AddClass("form-control");
        }