public static string RenderFormGroupTextArea(HtmlHelper html, TextAreaModel inputModel, LabelModel labelModel) { var input = RenderControl.RenderTextArea(html, inputModel); var label = RenderControl.RenderLabel(html, labelModel ?? new LabelModel { 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 FormGroup(input, label, FormGroupType.TextBoxLike, fieldIsValid).ToHtmlString(); }
public static HtmlString RenderTextArea(HtmlHelper html, TextAreaModel model) { string validationMessage = ""; if (model.displayValidationMessage) { string 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"); string 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; } string htmlString = inputWrapper != null ? inputWrapper.ToString(TagRenderMode.Normal) : htmlTextArea; return new HtmlString(htmlString); }