internal static string HtmlForListItemToOption(string name, SelectListItem item, SelectListLayout layout, bool allowMultiple) { var inputTag = new TagBuilder("input"); inputTag.Attributes.Add("type", (allowMultiple ? "checkbox" : "radio")); inputTag.Attributes.Add("name", name); if (item.Value != null) { inputTag.Attributes["value"] = item.Value; } if (item.Selected) { inputTag.Attributes["checked"] = "checked"; } // var labelTag = new TagBuilder("label"); labelTag.Attributes.Add("for", name); if (item.Text != null) { labelTag.SetInnerText(item.Text); } // var divTag = new TagBuilder("div"); if (layout.RepeatDirection == RepeatDirection.Horizontal) { divTag.AddCssStyle("float", "left"); } divTag.AddCssClass((allowMultiple ? "checkbox" : "radio") + "List"); divTag.InnerHtml = inputTag.ToString(TagRenderMode.Normal) + labelTag.ToString(TagRenderMode.Normal); return(divTag.ToString(TagRenderMode.Normal)); }
public static HtmlString RenderLabel(HtmlHelper html, LabelModel model) { var fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName); var innerinput = ""; if (string.IsNullOrEmpty(model.labelText)) model.labelText = model.metadata.DisplayName ?? (model.metadata.PropertyName != null ? model.metadata.PropertyName.SplitByUpperCase() : null) ?? fullHtmlFieldName.Split('.').Last().SplitByUpperCase(); var label = new TagBuilder("label"); label.Attributes.Add("for", fullHtmlFieldName.FormatForMvcInputId() + (model.index.HasValue ? "_" + model.index.Value : string.Empty)); label.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes()); var requiredSpan = new TagBuilder("span"); requiredSpan.AddCssClass("required"); requiredSpan.SetInnerText("*"); if ((model.showRequiredStar.HasValue && !model.showRequiredStar.Value) || (!model.showRequiredStar.HasValue && !model.metadata.IsRequired)) requiredSpan.AddCssStyle("visibility", "hidden"); if (model.innerInputType != InputType._NotSet) { if (model.innerInputType == InputType.CheckBox) { var inputModel = (CheckBoxModel) model.innerInputModel; //label.AddOrMergeCssClass("checkbox"); inputModel.displayValidationMessage = false; model.innerInput = MvcHtmlString.Create(inputModel.isSingleInput ? RenderCheckBoxCustom(html, inputModel).ToHtmlString() : RenderCheckBox(html, inputModel).ToHtmlString()); if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id")) label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString(); } if (model.innerInputType == InputType.Radio) { var inputModel = (RadioButtonModel) model.innerInputModel; model.innerInput = MvcHtmlString.Create(RenderRadioButton(html, inputModel).ToHtmlString()); if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id")) label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString(); } } if (model.innerInput != null) innerinput = model.innerInput.ToHtmlString(); label.InnerHtml = innerinput + model.labelText + requiredSpan + model.innerValidationMessage; return new HtmlString(label.ToString(TagRenderMode.Normal)); }
public string ToHtmlString() { TagBuilder ul = new TagBuilder("ul"); ul.MergeAttributes(_htmlAttributes.FormatHtmlAttributes()); if (_maxHeight.HasValue) { ul.AddCssStyle("max-height", _maxHeight.ToString() + "px"); ul.AddCssStyle("overflow-y", "scroll"); } ul.AddCssClass("dropdown-menu"); if (_alignToDirection == "right") { ul.AddCssClass("pull-right"); } _menuItems.ForEach(x => ul.InnerHtml += x.ToHtmlString()); return(ul.ToString(TagRenderMode.Normal)); }
public static string RenderDisplayText(HtmlHelper html, BootstrapDisplayTextModel model) { var input = html.DisplayText(model.htmlFieldName); TagBuilder containerDiv = new TagBuilder("div"); containerDiv.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes()); containerDiv.AddCssStyle("padding-top", "5px"); containerDiv.InnerHtml = input.ToHtmlString(); return containerDiv.ToString(TagRenderMode.Normal); }
public static string RenderDisplayText(HtmlHelper html, BootstrapDisplayTextModel model) { var input = html.DisplayText(model.htmlFieldName); TagBuilder containerDiv = new TagBuilder("div"); containerDiv.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes()); containerDiv.AddCssStyle("padding-top", "5px"); containerDiv.InnerHtml = input.ToHtmlString(); return(containerDiv.ToString(TagRenderMode.Normal)); }
private static MvcHtmlString SelectInternal(HtmlHelper htmlHelper, string name, IEnumerable <SelectListItem> items, SelectListLayout layout, bool allowMultiple, IDictionary <string, object> htmlAttributes) { ModelState state; name = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name); if (string.IsNullOrEmpty(name)) { throw new ArgumentException("MvcResources.Common_NullOrEmpty", "name"); } var hasItems = false; if (items == null) { items = GetSelectData(htmlHelper, name); hasItems = true; } object data = (allowMultiple ? htmlHelper.GetModelStateValue(name, typeof(string[])) : htmlHelper.GetModelStateValue(name, typeof(string))); if (!hasItems && data == null) { data = htmlHelper.ViewData.Eval(name); } if (data != null) { var source = (allowMultiple ? (data as IEnumerable) : ((IEnumerable) new object[] { data })); var set = new HashSet <string>(source.Cast <object>().Select <object, string>(value => Convert.ToString(value, CultureInfo.CurrentCulture)), StringComparer.OrdinalIgnoreCase); foreach (var item in items) { item.Selected = (item.Value != null ? set.Contains(item.Value) : set.Contains(item.Text)); } } var b = new TagBuilder("div"); if (layout.RepeatDirection == RepeatDirection.Horizontal) { b.AddCssStyle("clear", "both"); } b.InnerHtml = HtmlForSelectList(name, items, layout, allowMultiple); b.MergeAttributes <string, object>(htmlAttributes); b.GenerateId(name); if (htmlHelper.ViewData.ModelState.TryGetValue(name, out state) && (state.Errors.Count > 0)) { b.AddCssClass(HtmlHelper.ValidationInputCssClassName); } return(b.ToMvcHtmlString(TagRenderMode.Normal)); }
public static string RenderLabel(HtmlHelper html, BootstrapLabelModel model) { string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName); if (string.IsNullOrEmpty(model.labelText)) { model.labelText = model.metadata.DisplayName ?? (model.metadata.PropertyName != null ? model.metadata.PropertyName.SplitByUpperCase() : null) ?? fullHtmlFieldName.Split('.').Last().SplitByUpperCase(); } TagBuilder label = new TagBuilder("label"); label.Attributes.Add("for", fullHtmlFieldName.FormatForMvcInputId() + (model.index.HasValue ? "_" + model.index.Value.ToString() : string.Empty)); label.MergeAttributes(model.htmlAttributes.FormatHtmlAttributes()); TagBuilder requiredSpan = new TagBuilder("span"); requiredSpan.AddCssClass("required"); requiredSpan.SetInnerText("*"); if ((model.showRequiredStar.HasValue && !model.showRequiredStar.Value) || (!model.showRequiredStar.HasValue && !model.metadata.IsRequired)) { requiredSpan.AddCssStyle("visibility", "hidden"); } if (model.innerInputType != BootstrapInputType._NotSet) { if (model.innerInputType == BootstrapInputType.CheckBox) { label.AddOrMergeCssClass("checkbox"); BootstrapCheckBoxModel inputModel = (BootstrapCheckBoxModel)model.innerInputModel; inputModel.displayValidationMessage = false; model.innerInput = MvcHtmlString.Create(inputModel.isSingleInput ? Renderer.RenderCheckBoxCustom(html, inputModel) : Renderer.RenderCheckBox(html, inputModel)); if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id")) { label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString(); } } if (model.innerInputType == BootstrapInputType.Radio) { label.AddOrMergeCssClass("radio"); BootstrapRadioButtonModel inputModel = (BootstrapRadioButtonModel)model.innerInputModel; model.innerInput = MvcHtmlString.Create(Renderer.RenderRadioButton(html, inputModel)); if (inputModel.htmlAttributes.Keys.Select(x => x.ToLower()).Contains("id")) { label.Attributes["for"] = inputModel.htmlAttributes["id"].ToString(); } } } string innerinput = ""; if (model.innerInput != null) { innerinput = model.innerInput.ToHtmlString(); } label.InnerHtml = innerinput + model.labelText + requiredSpan.ToString() + model.innerValidationMessage; return(label.ToString(TagRenderMode.Normal)); }
public static string RenderRadioButtonTrueFalse(HtmlHelper html, BootstrapRadioButtonTrueFalseModel model) { TagBuilder inputsContainer = new TagBuilder("div"); inputsContainer.AddCssClass("container-radio-true-false"); inputsContainer.AddCssStyle("display", "inline-block"); inputsContainer.AddCssStyle("margin-top", "4px"); if (model.tooltipConfiguration != null) { inputsContainer.MergeAttributes(model.tooltipConfiguration.ToDictionary()); } if (model.tooltip != null) { inputsContainer.MergeAttributes(model.tooltip.ToDictionary()); } string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName); bool trueValueIsSelected = false; bool falseValueIsSelected = false; if (model.metadata.Model != null) { trueValueIsSelected = model.inputTrueValue.ToString() == model.metadata.Model.ToString(); falseValueIsSelected = model.inputTrueValue.ToString() != model.metadata.Model.ToString(); } var inputTrue = Renderer.RenderLabel(html, new BootstrapLabelModel { htmlFieldName = model.htmlFieldName, labelText = model.labelTrueText, metadata = model.metadata, htmlAttributes = model.htmlAttributesLabelTrue, showRequiredStar = false, innerInputType = BootstrapInputType.Radio, innerInputModel = new BootstrapRadioButtonModel { htmlFieldName = model.htmlFieldName, value = model.inputTrueValue, metadata = model.metadata, isChecked = trueValueIsSelected, htmlAttributes = model.htmlAttributesInputTrue.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_t") } }); var inputFalse = Renderer.RenderLabel(html, new BootstrapLabelModel { htmlFieldName = model.htmlFieldName, labelText = model.labelFalseText, metadata = model.metadata, htmlAttributes = model.htmlAttributesLabelFalse, showRequiredStar = false, innerInputType = BootstrapInputType.Radio, innerInputModel = new BootstrapRadioButtonModel { htmlFieldName = model.htmlFieldName, value = model.inputFalseValue, metadata = model.metadata, isChecked = falseValueIsSelected, htmlAttributes = model.htmlAttributesInputFalse.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_f") } }); string helpText = model.helpText != null?model.helpText.ToHtmlString() : string.Empty; string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } inputsContainer.InnerHtml = inputTrue + inputFalse; return(inputsContainer.ToString() + helpText + validationMessage); }
public static string RenderRadioButtonTrueFalse(HtmlHelper html, BootstrapRadioButtonTrueFalseModel model) { TagBuilder inputsContainer = new TagBuilder("div"); inputsContainer.AddCssClass("container-radio-true-false"); inputsContainer.AddCssStyle("display", "inline-block"); inputsContainer.AddCssStyle("margin-top", "4px"); if (model.tooltipConfiguration != null) inputsContainer.MergeAttributes(model.tooltipConfiguration.ToDictionary()); if (model.tooltip != null) inputsContainer.MergeAttributes(model.tooltip.ToDictionary()); string fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName); bool trueValueIsSelected = false; bool falseValueIsSelected = false; if (model.metadata.Model != null) { trueValueIsSelected = model.inputTrueValue.ToString() == model.metadata.Model.ToString(); falseValueIsSelected = model.inputTrueValue.ToString() != model.metadata.Model.ToString(); } var inputTrue = Renderer.RenderLabel(html, new BootstrapLabelModel { htmlFieldName = model.htmlFieldName, labelText = model.labelTrueText, metadata = model.metadata, htmlAttributes = model.htmlAttributesLabelTrue, showRequiredStar = false, innerInputType = BootstrapInputType.Radio, innerInputModel = new BootstrapRadioButtonModel { htmlFieldName = model.htmlFieldName, value = model.inputTrueValue, metadata = model.metadata, isChecked = trueValueIsSelected, htmlAttributes = model.htmlAttributesInputTrue.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_t") } }); var inputFalse = Renderer.RenderLabel(html, new BootstrapLabelModel { htmlFieldName = model.htmlFieldName, labelText = model.labelFalseText, metadata = model.metadata, htmlAttributes = model.htmlAttributesLabelFalse, showRequiredStar = false, innerInputType = BootstrapInputType.Radio, innerInputModel = new BootstrapRadioButtonModel { htmlFieldName = model.htmlFieldName, value = model.inputFalseValue, metadata = model.metadata, isChecked = falseValueIsSelected, htmlAttributes = model.htmlAttributesInputFalse.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_f") } }); string helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty; string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } inputsContainer.InnerHtml = inputTrue + inputFalse; return inputsContainer.ToString() + helpText + validationMessage; }
public static string RenderInputListContainer( HtmlHelper html, string htmlFieldName, List <string> inputs, int?numberOfColumns, bool displayInColumnsCondition, int columnPixelWidth, bool displayInlineBlock, int marginRightPx, bool displayValidationMessage, HelpTextStyle validationMessageStyle ) { TagBuilder container = new TagBuilder("div"); container.AddCssClass("input-list-container"); if (displayValidationMessage) { container.AddCssStyle("display", "inline-block"); container.AddCssStyle("vertical-align", "middle"); container.AddCssStyle("margin-top", "4px"); } if (numberOfColumns.HasValue && displayInColumnsCondition) { container.AddCssStyle("max-width", (columnPixelWidth * numberOfColumns).ToString() + "px"); List <string> columnedInputs = new List <string>(); TagBuilder columnDiv = new TagBuilder("div"); columnDiv.AddCssClass("input-list-column"); columnDiv.AddCssStyle("width", columnPixelWidth.ToString() + "px"); columnDiv.AddCssStyle("display", "inline-block"); foreach (var input in inputs) { columnDiv.InnerHtml = input; columnedInputs.Add(columnDiv.ToString()); } inputs = columnedInputs; } if (displayInlineBlock) { List <string> columnedInputs = new List <string>(); TagBuilder columnDiv = new TagBuilder("div"); columnDiv.AddCssClass("input-list-inline"); columnDiv.AddCssStyle("display", "inline-block"); columnDiv.AddCssStyle("margin-right", marginRightPx.ToString() + "px"); foreach (var input in inputs) { columnDiv.InnerHtml = input; columnedInputs.Add(columnDiv.ToString()); } inputs = columnedInputs; } string inputsCombined = string.Empty; inputs.ForEach(c => inputsCombined += c); container.InnerHtml = inputsCombined; string validationMessage = ""; if (displayValidationMessage) { string validation = html.ValidationMessage(htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, validationMessageStyle).ToHtmlString(); } return(container.ToString(TagRenderMode.Normal) + validationMessage); }
public static string RenderInputListContainer( HtmlHelper html, string htmlFieldName, List<string> inputs, int? numberOfColumns, bool displayInColumnsCondition, int columnPixelWidth, bool displayInlineBlock, int marginRightPx, bool displayValidationMessage, HelpTextStyle validationMessageStyle ) { TagBuilder container = new TagBuilder("div"); container.AddCssClass("input-list-container"); if (displayValidationMessage) { //container.AddCssStyle("display", "inline-block"); //container.AddCssStyle("vertical-align", "middle"); //container.AddCssStyle("margin-top", "4px"); } if (numberOfColumns.HasValue && displayInColumnsCondition) { container.AddCssStyle("max-width", (columnPixelWidth * numberOfColumns).ToString() + "px"); List<string> columnedInputs = new List<string>(); TagBuilder columnDiv = new TagBuilder("div"); //columnDiv.AddCssClass("input-list-column"); //columnDiv.AddCssStyle("width", columnPixelWidth.ToString() + "px"); //columnDiv.AddCssStyle("display", "inline-block"); foreach (var input in inputs) { columnDiv.InnerHtml = input; columnedInputs.Add(columnDiv.ToString()); } inputs = columnedInputs; } if (displayInlineBlock) { List<string> columnedInputs = new List<string>(); TagBuilder columnDiv = new TagBuilder("div"); //columnDiv.AddCssClass("input-list-inline"); //columnDiv.AddCssStyle("display", "inline-block"); //columnDiv.AddCssStyle("margin-right", marginRightPx.ToString() + "px"); foreach (var input in inputs) { columnDiv.InnerHtml = input; columnedInputs.Add(columnDiv.ToString()); } inputs = columnedInputs; } string inputsCombined = string.Empty; inputs.ForEach(c => inputsCombined += c); container.InnerHtml = inputsCombined; string validationMessage = ""; if (displayValidationMessage && html.ValidationMessage(htmlFieldName) != null) { string validation = html.ValidationMessage(htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, validationMessageStyle).ToHtmlString(); } return container.ToString(TagRenderMode.Normal) + validationMessage; }
public static HtmlString RenderInputListContainer(HtmlHelper html, string htmlFieldName, List<string> inputs, int? numberOfColumns, bool displayInColumnsCondition, int columnPixelWidth, bool displayInlineBlock, int marginRightPx, bool displayValidationMessage, HelpTextStyle validationMessageStyle, InputType inputType, CheckBoxRadioStyle inputStyle) { var cssClass = inputType == InputType.CheckBoxList ? "checkbox" : "radio"; var displayStyle = inputStyle == CheckBoxRadioStyle.Block ? "form-block" : "form-inline"; var container = new TagBuilder("div"); container.AddCssClass($"{cssClass} {displayStyle}"); if (displayValidationMessage) { container.AddCssStyle("display", "inline-block"); container.AddCssStyle("vertical-align", "middle"); container.AddCssStyle("margin-top", "4px"); } if (numberOfColumns.HasValue && displayInColumnsCondition) { container.AddCssStyle("max-width", columnPixelWidth*numberOfColumns + "px"); var columnedInputs = new List<string>(); var columnDiv = new TagBuilder("div"); columnDiv.AddCssClass("input-list-column"); columnDiv.AddCssStyle("width", columnPixelWidth + "px"); columnDiv.AddCssStyle("display", "inline-block"); foreach (var input in inputs) { columnDiv.InnerHtml = input; columnedInputs.Add(columnDiv.ToString()); } inputs = columnedInputs; } if (displayInlineBlock) { var columnedInputs = new List<string>(); var columnDiv = new TagBuilder("div"); columnDiv.AddCssClass("input-list-inline"); columnDiv.AddCssStyle("display", "inline-block"); columnDiv.AddCssStyle("margin-right", marginRightPx + "px"); foreach (var input in inputs) { columnDiv.InnerHtml = input; columnedInputs.Add(columnDiv.ToString()); } inputs = columnedInputs; } var inputsCombined = string.Empty; inputs.ForEach(c => inputsCombined += c); container.InnerHtml = inputsCombined; var validationMessage = ""; if (displayValidationMessage) { var validation = html.ValidationMessage(htmlFieldName).ToHtmlString(); validationMessage = new HelpText(validation, validationMessageStyle).ToHtmlString(); } return new HtmlString(container.ToString(TagRenderMode.Normal) + validationMessage); }
protected override void Render(TagHelperContext context, TagHelperOutput output) { output.SetTagName("div"); output.AddCssClass("progress-bar"); output.TagMode = TagMode.StartTagAndEndTag; // Value if (Value > 100) { Value = 100; } output.MergeAttribute("aria-valuemin", "0"); output.MergeAttribute("aria-valuemax", "100"); output.MergeAttribute("aria-valuenow", Value.ToString()); output.MergeAttribute("role", "progressbar"); if (IsVertical) { output.AddCssStyle("height", Value.ToString() + "%"); } else { output.AddCssStyle("width", Value.ToString() + "%"); } // Color if (Color != ProgressBarTagColor.Default) { output.AddCssClass(this.Color.GetEnumInfo().Name); } // Label if (this.IsLabeled) { output.AddCssStyle("min-width", "3em"); output.PreContent.Append(Value.ToString() + "%"); } // Animated and Striped if (this.IsAnimated) { output.AddCssClass("progress-bar-striped"); output.AddCssClass("active"); } else if (this.IsStriped) { output.AddCssClass("progress-bar-striped"); } if (ProgressStackContext == null) { TagBuilder wrapper = new TagBuilder("div") { TagRenderMode = TagRenderMode.Normal }; wrapper.AddCssClass("progress"); if (IsVertical) { if (Height == 0) { Height = 200; } if (Width == 0) { Width = 30; } //wrapper.AddCssClass("vertical"); wrapper.AddCssStyle("position", "relative"); wrapper.AddCssStyle("display", "inline-block"); wrapper.AddCssStyle("height", Height + "px"); wrapper.AddCssStyle("width", Width + "px"); output.AddCssStyle("width", "100%"); output.AddCssStyle("position", "absolute"); output.AddCssStyle("bottom", "0"); } else { if (this.Height > 0) { wrapper.AddCssStyle("height", Height + "px"); } } output.WrapOutside(wrapper); } }