コード例 #1
0
        public static string RenderFile(HtmlHelper html, BootstrapFileModel model)
        {
            string validationMessage = "";

            if (model.displayValidationMessage)
            {
                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);
        }
コード例 #2
0
        public static string RenderFormGroupFile(HtmlHelper html, BootstrapFileModel inputModel, BootstrapLabelModel labelModel)
        {
            var input = Renderer.RenderFile(html, inputModel);

            string label = Renderer.RenderLabel(html, labelModel ?? new BootstrapLabelModel
            {
                htmlFieldName  = inputModel.htmlFieldName,
                metadata       = inputModel.metadata,
                htmlAttributes = new { @class = "control-label" }.ToDictionary()
            });

            bool fieldIsValid = true;

            if (inputModel != null)
            {
                fieldIsValid = html.ViewData.ModelState.IsValidField(inputModel.htmlFieldName);
            }
            return(new BootstrapFormGroup(input, label, FormGroupType.textboxLike, fieldIsValid).ToHtmlString());
        }