public static string RenderFile(HtmlHelper html, BootstrapFileModel model) { if (model == null || string.IsNullOrEmpty(model.htmlFieldName)) return null; string validationMessage = ""; if (model.displayValidationMessage) { string validation = html.ValidationMessage(model.htmlFieldName).ToHtmlString(); validationMessage = new BootstrapHelpText(validation, model.validationMessageStyle).ToHtmlString(); } if (model.tooltipConfiguration != null) model.htmlAttributes.AddRange(model.tooltipConfiguration.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; }
public static string RenderControlGroupFile(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 BootstrapControlGroup(input, label, ControlGroupType.textboxLike, fieldIsValid).ToHtmlString(); }