当前位置: 首页>>代码示例>>C#>>正文


C# HtmlHelper.ValidationMessage方法代码示例

本文整理汇总了C#中System.Web.Mvc.HtmlHelper.ValidationMessage方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.ValidationMessage方法的具体用法?C# HtmlHelper.ValidationMessage怎么用?C# HtmlHelper.ValidationMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.HtmlHelper的用法示例。


在下文中一共展示了HtmlHelper.ValidationMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderCheckBox

        public static string RenderCheckBox(HtmlHelper html, BootstrapCheckBoxModel model)
        {
            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
            if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            var mergedHtmlAttrs = string.IsNullOrEmpty(model.id) ? model.htmlAttributes : model.htmlAttributes.AddOrReplace("id", model.id);

            string validationMessage = "";
            if(model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }
            return html.CheckBox(model.htmlFieldName, model.isChecked, mergedHtmlAttrs.FormatHtmlAttributes()).ToHtmlString() + validationMessage;
        }
开发者ID:ngadotnet,项目名称:TwitterBootstrapMvc,代码行数:15,代码来源:Renderer.CheckBox.cs

示例2: RenderTextArea

        public static string RenderTextArea(HtmlHelper html, BootstrapTextAreaModel model)
        {
            string validationMessage = "";
            if(model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }
            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
            if(!string.IsNullOrEmpty(model.id)) model.htmlAttributes.AddOrReplace("id", model.id);

            if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());

            return html.TextArea(model.htmlFieldName, model.value, model.rows, model.columns, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() + validationMessage;
        }
开发者ID:ngadotnet,项目名称:TwitterBootstrapMvc,代码行数:16,代码来源:Renderer.TextArea.cs

示例3: RenderFormGroupRadioButton

        public static string RenderFormGroupRadioButton(HtmlHelper html, RadioButtonModel inputModel, LabelModel labelModel)
        {
            var validationMessage = "";
            var radioType = "form-icon";

            if (inputModel.displayValidationMessage)
            {
                var validation = html.ValidationMessage(inputModel.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, inputModel.validationMessageStyle).ToHtmlString();
            }

            if (labelModel == null && inputModel.RadioType != InputRadioCheckBoxType._NotSet)
                radioType = inputModel.RadioType.ToName();

            var label = RenderLabel(html, labelModel ?? new LabelModel
            {
                htmlFieldName = inputModel.htmlFieldName,
                metadata = inputModel.metadata,
                innerInputType = InputType.Radio,
                innerInputModel = inputModel,
                innerValidationMessage = validationMessage,
                htmlAttributes = new {@class = $"form-radio {radioType} form-text"}.ToDictionary()
            });

            var fieldIsValid = true;

            if (inputModel != null)
                fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName);

            return new FormGroup(null, label, FormGroupType.CheckBoxLike, fieldIsValid).ToHtmlString();
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:31,代码来源:RenderFormGroupRadioButton.cs

示例4: RenderFile

        public static string RenderFile(HtmlHelper html, BootstrapFileModel model)
        {
            string validationMessage = "";
            if(model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());

            var mergedHtmlAttrs = model.htmlAttributes.FormatHtmlAttributes().AddOrReplace("type", "File");
            if (!string.IsNullOrEmpty(model.id)) mergedHtmlAttrs.AddOrReplace("id", model.id);

            return html.TextBox(model.htmlFieldName, null, mergedHtmlAttrs).ToHtmlString() + validationMessage;
        }
开发者ID:ngadotnet,项目名称:TwitterBootstrapMvc,代码行数:19,代码来源:Renderer.File.cs

示例5: RenderCheckBox

        public static HtmlString RenderCheckBox(HtmlHelper html, CheckBoxModel model)
        {
            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            var mergedHtmlAttrs = string.IsNullOrEmpty(model.id) ? model.htmlAttributes : model.htmlAttributes.AddOrReplace("id", model.id);

            string validationMessage = "";

            if (model.displayValidationMessage)
            {
                string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return new HtmlString(html.CheckBox(model.htmlFieldName, model.isChecked, mergedHtmlAttrs.FormatHtmlAttributes()).ToHtmlString() + validationMessage);
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:16,代码来源:RenderCheckBox.cs

示例6: RenderTextArea

        public static HtmlString RenderTextArea(HtmlHelper html, TextAreaModel model)
        {
            var validationMessage = "";

            if (model.displayValidationMessage)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id))
                model.htmlAttributes.AddOrReplace("id", model.id);

            if (!string.IsNullOrEmpty(model.placeholder))
                model.htmlAttributes.Add("placeholder", model.placeholder);

            model.htmlAttributes.AddOrMergeCssClass("class", "form-control");

            var htmlTextArea =
                html.TextArea(model.htmlFieldName, model.value, model.rows, model.columns,
                    model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString() + validationMessage;

            TagBuilder inputWrapper = null;

            if (!string.IsNullOrEmpty(model.inputElementWrapper))
            {
                inputWrapper = new TagBuilder(model.inputElementWrapper);

                if (model.inputElementWrapperAttributes != null)
                    inputWrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(model.inputElementWrapperAttributes));

                inputWrapper.InnerHtml = htmlTextArea;
            }

            var htmlString = inputWrapper != null
                ? inputWrapper.ToString(TagRenderMode.Normal)
                : htmlTextArea;

            return new HtmlString(htmlString);
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:42,代码来源:RenderTextArea.cs

示例7: RenderRadioButton

        public static HtmlString RenderRadioButton(HtmlHelper html, RadioButtonModel model)
        {
            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id))
                model.htmlAttributes.AddOrReplace("id", model.id);

            var validationMessage = "";

            if (model.displayValidationMessage)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return
                new HtmlString(
                    html.RadioButton(model.htmlFieldName, model.value, model.isChecked, model.htmlAttributes.FormatHtmlAttributes())
                        .ToHtmlString() + validationMessage);
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:20,代码来源:RenderRadioButton.cs

示例8: RenderControlGroupRadioButton

        public static string RenderControlGroupRadioButton(HtmlHelper html, BootstrapRadioButtonModel inputModel, BootstrapLabelModel labelModel)
        {
            string validationMessage = "";
            if (inputModel.displayValidationMessage)
            {
                string validation = html.ValidationMessage(inputModel.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, inputModel.validationMessageStyle).ToHtmlString();
            }

            string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel
            {
                htmlFieldName = inputModel.htmlFieldName,
                metadata = inputModel.metadata,
                innerInputType = BootstrapInputType.Radio,
                innerInputModel = inputModel,
                innerValidationMessage = validationMessage
            });

            bool fieldIsValid = true;
            if(inputModel != null) fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName);
            return new BootstrapControlGroup(null, label, ControlGroupType.checkboxLike, fieldIsValid).ToHtmlString();
        }
开发者ID:canicelebrate,项目名称:TwitterBootstrapMvc,代码行数:22,代码来源:Renderer.ControlGroup.RadioButton.cs

示例9: RenderDropDownForEnum

        public string RenderDropDownForEnum(HtmlHelper htmlHelper, PropertyInfo property, object value)
        {
            var items = GetDropDownItems(property);

            var dropDownHtml = htmlHelper
                .DropDownList(property.Name, items, UiTexts.Editor_DropDown_EmptyValue, new { @class = "form-control" })
                .ToHtmlString();

            dropDownHtml = this.SelectProperItem(dropDownHtml, value);

            if (property.GetAttribute<RequiredAttribute>() == null)
            {
                dropDownHtml = dropDownHtml.Replace("data-val=\"true\"", string.Empty);
            }

            var validationMessage = htmlHelper.ValidationMessage(property.Name, string.Empty, new { @class = "text-danger" });
            if (validationMessage != null)
            {
                dropDownHtml += validationMessage.ToHtmlString();
            }

            return dropDownHtml;
        }
开发者ID:dwdkls,项目名称:pizzamvc,代码行数:23,代码来源:DropDownRendererBase.cs

示例10: RenderRadioButtonPair

        public static HtmlString RenderRadioButtonPair(HtmlHelper html, RadioButtonPairModel model)
        {
            TagBuilder wrapper = null;
            var inputPairs = string.Empty;
            var fullHtmlFieldName = html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(model.htmlFieldName);
            var radioType = "form-icon";

            var pairOneValueIsSelected = false;
            var pairTwoValueIsSelected = false;

            if (model.metadata.Model != null)
            {
                pairOneValueIsSelected = model.inputPairOneValue.ToString() == model.metadata.Model.ToString();
                pairTwoValueIsSelected = model.inputPairOneValue.ToString() != model.metadata.Model.ToString();
            }

            if (model.RadioType != InputRadioCheckBoxType._NotSet)
                radioType = model.RadioType.ToName();

            var inputPairOne = RenderLabel(html, new LabelModel
            {
                htmlFieldName = model.htmlFieldName,
                labelText = model.labelPairOneText,
                metadata = model.metadata,
                htmlAttributes = model.htmlAttributesLabelPairOne.AddOrMergeCssClass("class", $"form-radio {radioType} form-text"),
                showRequiredStar = false,
                innerInputType = InputType.Radio,
                innerInputModel = new RadioButtonModel
                {
                    htmlFieldName = model.htmlFieldName,
                    value = model.inputPairOneValue,
                    metadata = model.metadata,
                    isChecked = pairOneValueIsSelected,
                    RadioType = model.RadioType,
                    htmlAttributes =
                        model.htmlAttributesInputPairOne.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_pairOne")
                }
            });

            var inputPairTwo = RenderLabel(html, new LabelModel
            {
                htmlFieldName = model.htmlFieldName,
                labelText = model.labelPairTwoText,
                metadata = model.metadata,
                htmlAttributes = model.htmlAttributesLabelPairTwo.AddOrMergeCssClass("class", $"form-radio {radioType} form-text"),
                showRequiredStar = false,
                innerInputType = InputType.Radio,
                innerInputModel = new RadioButtonModel
                {
                    htmlFieldName = model.htmlFieldName,
                    value = model.inputPairTwoValue,
                    metadata = model.metadata,
                    isChecked = pairTwoValueIsSelected,
                    RadioType = model.RadioType,
                    htmlAttributes =
                        model.htmlAttributesInputPairTwo.AddOrReplace("id", fullHtmlFieldName.FormatForMvcInputId() + "_pairTwo")
                }
            });

            var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            var validationMessage = "";

            if (model.displayValidationMessage)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            if (model.RadioStyle == CheckBoxRadioStyle.Block)
            {
                var wrapperPairOne = new TagBuilder("div");
                var wrapperPairTwo = new TagBuilder("div");

                wrapperPairOne.AddCssClass("radio");
                wrapperPairOne.InnerHtml = inputPairOne.ToHtmlString();
                wrapperPairTwo.AddCssClass("radio");
                wrapperPairTwo.InnerHtml = inputPairTwo.ToHtmlString();

                inputPairs = wrapperPairOne + wrapperPairTwo.ToString();
            }
            else if (model.RadioStyle == CheckBoxRadioStyle.Inline)
            {
                var inputsWrapper = new TagBuilder("div");
                inputsWrapper.AddCssClass("radio");
                inputsWrapper.InnerHtml = inputPairOne.ToHtmlString() + inputPairTwo.ToHtmlString();

                inputPairs = inputsWrapper.ToString();
            }

            if (!string.IsNullOrEmpty(model.radioPairElementWrapper))
            {
                wrapper = new TagBuilder(model.radioPairElementWrapper);

                if (model.radioPairElementWrapperAttributes != null)
                    wrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(model.radioPairElementWrapperAttributes));

                wrapper.InnerHtml = inputPairs;
            }

            var htmlString = wrapper != null
//.........这里部分代码省略.........
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:101,代码来源:RenderRadioButtonPair.cs

示例11: RenderInputListContainer

        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);
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:68,代码来源:RenderInputListContainer.cs

示例12: RenderDatePicker


//.........这里部分代码省略.........

            if(model.multidate)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.multidate), model.multidate.ToString().ToLower());

            if(!string.IsNullOrEmpty(model.multidateSeparator))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.multidateSeparator), model.multidateSeparator);

            if(!string.IsNullOrEmpty(model.orientation))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.orientation), model.orientation);

            if(!model.showOnFocus)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.showOnFocus), model.showOnFocus.ToString().ToLower());

            if(model.startDate != null)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.startDate), model.startDate.ToString());

            if(model.startView != 0)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.startView), model.startView.ToString());

            if(!string.IsNullOrEmpty(model.title))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.title), model.title);

            if(!string.IsNullOrEmpty(model.todayBtn))
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.todayBtn), model.todayBtn);

            if (model.todayHighlight)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.todayHighlight), model.todayHighlight.ToString().ToLower());

            if(model.toggleActive)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.toggleActive), model.toggleActive.ToString().ToLower());

            if(model.zIndexOffset != 10)
                model.htmlAttributes.AddOrReplace(model.HtmlAttr(() => model.zIndexOffset), model.zIndexOffset.ToString());

            htmlAttributes.MergeHtmlAttributes(model.htmlAttributes.FormatHtmlAttributes());

            var input = html.TextBox(model.htmlFieldName, model.value, model.format, htmlAttributes).ToHtmlString();

            container.AddOrMergeCssClass("input-group");
            //container.AddOrMergeCssClass("date-picker");
            addOn.AddCssClass("input-group-addon");

            addOn.InnerHtml = new Icon(Icons.Calendar, Size.Lg).ToHtmlString();
            addOnAppendIcon = addOn.ToString();

            if (!string.IsNullOrEmpty(model.prependString) || model.iconPrepend != Icons._not_set || !string.IsNullOrEmpty(model.iconPrependCustomClass))
            {
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }

                if (model.iconPrepend != Icons._not_set)
                {
                    addOn.InnerHtml = new Icon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }

                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
            }

            container.InnerHtml = addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendIcon;
            combinedHtml = container.ToString(TagRenderMode.Normal) + "{1}{2}";

            var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            var validationMessage = "";

            if (model.displayValidationMessage)
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new HelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            string htmlTextBox = string.Format(combinedHtml, input, helpText, validationMessage);

            TagBuilder inputWrapper = null;

            if (!string.IsNullOrEmpty(model.inputElementWrapper))
            {
                inputWrapper = new TagBuilder(model.inputElementWrapper);

                if (model.inputElementWrapperAttributes != null)
                    inputWrapper.MergeAttributes(HtmlHelper.AnonymousObjectToHtmlAttributes(model.inputElementWrapperAttributes));

                inputWrapper.InnerHtml = htmlTextBox;
            }

            string htmlString = inputWrapper != null
                ? inputWrapper.ToString(TagRenderMode.Normal)
                : htmlTextBox;

            return new HtmlString(htmlString);
        }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:101,代码来源:RenderDatePicker.cs

示例13: RenderSelectElement

        public static string RenderSelectElement(HtmlHelper html, BootstrapSelectElementModel model, BootstrapInputType inputType)
        {
            string combinedHtml = "{0}{1}{2}";
            if (model.selectedValue != null)
            {
                foreach (var item in model.selectList)
                {
                    if (item.Value == model.selectedValue.ToString())
                        item.Selected = true;
                }
            }

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));
            if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.AddOrReplace("id", model.id);

            // assign size class
            model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));

            // build html for input
            string input = string.Empty;

            if(inputType == BootstrapInputType.DropDownList)
                input = html.DropDownList(model.htmlFieldName, model.selectList, model.optionLabel, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            if(inputType == BootstrapInputType.ListBox)
                input = html.ListBox(model.htmlFieldName, model.selectList, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            // account for appendString, prependString, and AppendButtons
            TagBuilder appendPrependContainer = new TagBuilder("div");
            if (!string.IsNullOrEmpty(model.prependString) | !string.IsNullOrEmpty(model.appendString) | model.appendButtons.Count() > 0)
            {
                string addOnPrependString = "";
                string addOnAppendString = "";
                string addOnPrependButtons = "";
                string addOnAppendButtons = "";

                TagBuilder addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.appendButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    ((List<BootstrapButton>)model.appendButtons).ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.prependButtons.Count() > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    ((List<BootstrapButton>)model.prependButtons).ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependString + "{0}" + addOnAppendString + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            string helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            string validationMessage = "";
            if(model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
            {
                string validation = html.ValidationMessage((string)model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
            }

            return MvcHtmlString.Create(string.Format(combinedHtml, input, helpText, validationMessage)).ToString();
        }
开发者ID:ngadotnet,项目名称:TwitterBootstrapMvc,代码行数:77,代码来源:Renderer.SelectElement.cs

示例14: RenderRadioButtonTrueFalse

        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;
        }
开发者ID:canicelebrate,项目名称:TwitterBootstrapMvc,代码行数:66,代码来源:Renderer.RadioButtonTrueFalse.cs

示例15: RenderTextBox

        public static string RenderTextBox(HtmlHelper html, BootstrapTextBoxModel model, bool isPassword)
        {
            var combinedHtml = "{0}{1}{2}";

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.Add("id", model.id);
            if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            if (model.typehead != null) model.htmlAttributes.MergeHtmlAttributes(model.typehead.ToDictionary(html));
            // assign placeholder class
            if (!string.IsNullOrEmpty(model.placeholder)) model.htmlAttributes.Add("placeholder", model.placeholder);
            // assign size class
            model.htmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForInputSize(model.size));
            // build html for input
            var input = isPassword
                ? html.Password(model.htmlFieldName, null, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString()
                : html.TextBox(model.htmlFieldName, model.value, model.format, model.htmlAttributes.FormatHtmlAttributes()).ToHtmlString();

            // account for appendString, prependString, and AppendButtons
            if (!string.IsNullOrEmpty(model.prependString) ||
                !string.IsNullOrEmpty(model.appendString) ||
                model.prependButtons.Any() ||
                model.appendButtons.Any() ||
                model.iconPrepend != Icons._not_set ||
                model.iconAppend != Icons._not_set ||
                !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
                !string.IsNullOrEmpty(model.iconAppendCustomClass))
            {
                var appendPrependContainer = new TagBuilder("div");
                var addOnPrependString = "";
                var addOnAppendString = "";
                var addOnPrependButtons = "";
                var addOnAppendButtons = "";
                var addOnPrependIcon = "";
                var addOnAppendIcon = "";

                var addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.prependButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }
                if (model.appendButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.iconPrepend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }
                if (model.iconAppend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
                    addOnAppendIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconAppendCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnAppendIcon = addOn.ToString();
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

            var helpText = model.helpText != null ? model.helpText.ToHtmlString() : string.Empty;
            var validationMessage = "";
            if (model.displayValidationMessage && html.ValidationMessage(model.htmlFieldName) != null )
            {
                var validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString();
                validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString();
//.........这里部分代码省略.........
开发者ID:ngadotnet,项目名称:TwitterBootstrapMvc,代码行数:101,代码来源:Renderer.TextBox.cs


注:本文中的System.Web.Mvc.HtmlHelper.ValidationMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。