public override string ToHtmlString() { var tag = CreateTag(); var label = new HtmlTagBuilder("label"); string id = Context.Id; if (!string.IsNullOrWhiteSpace(id) && !Context.AllowMultiple) { label.Attributes.Add("for", id); } if (Context.IsHidden) { label.MergeAttribute("style", "display: none;", true); } if (Context.IsInvisible) { label.AddCssClass("invisible"); } label.InnerHtml = tag.ToString() + Context.Header; string name = Context.Name; if (Context.IsInline) { if (!string.IsNullOrWhiteSpace(name)) { label.Attributes.Add("data-container-for", name); } label.AddCssClass("radio-inline"); return(label.ToString()); } string output = "<div class='" + (Context.AllowMultiple ? "checkbox" : "radio") + "'"; if (!string.IsNullOrWhiteSpace(name)) { output += " data-container-for='" + name + "'"; } output += ">" + label.ToString() + "</div>"; string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { output += "<div class='help-block'>" + description + "</div>"; } return(output); }
protected virtual void AddClearFix(StringBuilder cells, string className, bool endOfRow) { if (endOfRow) { var cell = new HtmlTagBuilder("div"); cell.AddCssClass("clearfix"); cell.AddCssClass(className); cells.Append(cell.ToString()); } }
public string ToHtmlString() { var tag = CreateTag(); bool requiresContainer = false; string output = ""; string header = Context.Header; if (header != null) { requiresContainer = true; if (string.IsNullOrWhiteSpace(Context.Id)) { output += "<label>"; } else { output += "<label for='" + Context.Id + "'>"; } output += header + "</label>"; } output += tag.ToString(); string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { requiresContainer = true; output += "<div class='help-block'>" + description + "</div>"; } string name = Context.Name; if (!requiresContainer) { if (!string.IsNullOrWhiteSpace(name)) { tag.MergeAttribute("data-container-for", name); } return(tag.ToString()); } var div = new HtmlTagBuilder("div"); if (!string.IsNullOrWhiteSpace(name)) { div.Attributes.Add("data-container-for", name); } div.AddCssClass("form-group"); div.InnerHtml = output; return(div.ToString()); }
public override string ToHtmlString() { var tag = CreateTag(); var label = new HtmlTagBuilder("label"); string id = Context.Id; if (!string.IsNullOrWhiteSpace(id)) { label.Attributes.Add("for", id); } label.InnerHtml = tag.ToString() + Context.Header; string name = Context.Name; HtmlTagBuilder container; if (!Context.IsInline) { label.AddCssClass("clearfix"); container = new HtmlTagBuilder("div"); container.AddCssClass("form-group"); } else { label.AddCssClass("checkbox-inline"); container = label; } if (!string.IsNullOrWhiteSpace(name)) { container.MergeAttribute("data-container-for", name); } if (Context.IsHidden) { container.MergeAttribute("style", "display: none;", true); } if (Context.IsInvisible) { container.AddCssClass("invisible"); } if (!Context.IsInline) { string output = "<div class='checkbox'>" + label.ToString() + "</div>"; string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { output += "<div class='help-block'>" + description + "</div>"; } container.InnerHtml = output; } return(container.ToString()); }
public TControl Begin() { if (_begun) { throw new Exception("Already called Begin"); } string name = Context.Name; string id = Context.Id; var div = new HtmlTagBuilder("div"); if (!string.IsNullOrWhiteSpace(name)) { div.Attributes.Add("data-container-for", name); } if (!string.IsNullOrWhiteSpace(id)) { div.Attributes.Add("data-group", id); } if (Context.IsHidden) { div.Attributes.Add("style", "display: none;"); } if (Context.IsInvisible) { div.AddCssClass("invisible"); } div.AddCssClass("form-group"); div.AddCssClass("has-feedback"); var context = HtmlHelper.ViewContext; context.Writer.Write(div.ToString(TagRenderMode.StartTag)); string header = Context.Header; if (header != null) { if (string.IsNullOrWhiteSpace(name)) { context.Writer.Write("<label>"); } else { context.Writer.Write("<label for='" + name + "'>"); } context.Writer.Write(header + "</label>"); if (!string.IsNullOrWhiteSpace(name)) { context.Writer.Write("<span class='field-validation-valid' data-valmsg-for='" + name + "' data-valmsg-replace='true'></span>"); } } string description = Context.Description; if (!string.IsNullOrWhiteSpace(description)) { context.Writer.Write("<div class='help-block'>" + description + "</div>"); } var tag = new HtmlTagBuilder(TagType); tag.MergeAttributes(Context.HtmlAttributes); tag.MergeIfAttribute("readonly", "readonly", Context.IsReadOnly); tag.MergeIfAttribute("disabled", "disabled", Context.IsDisabled); context.Writer.Write(tag.ToString(TagRenderMode.StartTag)); _begun = true; return((TControl)this); }
protected override string WrapTag(TagBuilder tag) { string imageId = Context.Id + "_Image"; string imageName = FullHtmlFieldName + "_Image"; var img = new HtmlTagBuilder("img"); img.AddCssClass("img-preview"); img.Attributes.Add("id", imageId); img.Attributes.Add("name", imageName); string selected; if (!string.IsNullOrEmpty(Context.FileName)) { img.Attributes.Add("src", Context.FileName); selected = " selected"; } else { selected = ""; } string output = tag.ToString() + "<div class='filepicker'>" + img.ToString() + "<div class='filepicker-buttons" + selected + "'>"; bool havePreAppend = Context.Append.Count > 0 || Context.Prepend.Count > 0; bool moreButtons = Context.CanRotate || Context.CanCrop || havePreAppend; if (!moreButtons && (Context.CanDelete || Context.CanCapture)) { output += "<div class='btn-group'>"; } if (Context.Button == null) { Button(Context.FileType == FilePickerContext.ImageFileType ? "Add Image" : "Add File"); } var button = Context.Button.Id(Context.Id + "_Button"); var htmlAttributes = (IDictionary <string, object>)HtmlHelper.AnonymousObjectToHtmlAttributes(button.Context.HtmlAttributes); AdditionalButtonAttributes(htmlAttributes); button.HtmlAttributes(htmlAttributes); output += button.ToString(); if (moreButtons) { output += " <br /><div class='btn-group'>"; } output += GetPreAppendString(Context.Prepend).ToString(); if (Context.CanCapture) { output += " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-info'" + " data-file-capture-for='" + Context.Id + "'" + " data-file-type='" + Context.FileType + "'" + " title='Webcam Capture'>" + "<span class='fa fa-camera'></span>" + " </button>" + " </span>"; } if (Context.CanRotate) { output += " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-success'" + " data-file-rotate-for='" + Context.Id + "'" + " data-file-url='" + UrlHelper.Action("RotateLeft", Context.ControllerName, new { id = "_ID_" }) + "'" + " title='Rotate image anti-clockwise'>" + "<span class='fa fa-rotate-left'></span>" + " </button>" + " </span>" + " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-success'" + " data-file-rotate-for='" + Context.Id + "'" + " data-file-url='" + UrlHelper.Action("RotateRight", Context.ControllerName, new { id = "_ID_" }) + "'" + " title='Rotate image clockwise'>" + "<span class='fa fa-rotate-right'></span>" + " </button>" + " </span>"; } if (Context.CanCrop) { output += " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-success'" + " data-file-crop-for='" + Context.Id + "'" + " data-file-url='" + UrlHelper.Action("Crop", Context.ControllerName) + "'" + " title='Crop image'>" + "<span class='fa fa-crop'></span>" + " </button>" + " </span>" + "<input id='" + Context.Id + "_Crop' name='" + Context.Id + "_Crop' type='hidden' />"; } output += GetPreAppendString(Context.Append).ToString(); if (Context.CanDelete) { output += " <span class='input-group-btn'>" + " <button" + " type='button' class='btn btn-danger'" + " data-file-cancel-for='" + Context.Id + "'" + " data-file-type='" + Context.FileType + "'" + " title='Delete'>" + "<span class='fa fa-trash-o'></span>" + " </button>" + " </span>"; } if (moreButtons || Context.CanDelete || Context.CanCapture) { output += " </div>"; // btn-group } output += " </div>" // filepicker-buttons + " <span id='" + Context.Id + "_FileName'>" + GeneratePlaceholder() + "</span>" + " <div id='" + Context.Id + "_ProgressContainer'>" + " <div id='" + Context.Id + "_ProgressPercent'>100%</div>" + " <div class='progress progress-striped active'>" + " <div id='" + Context.Id + "_Progress' class='progress-bar' role='progressbar'></div>" + " </div>" // progress + " </div>" // ProgressContainer + "</div>"; // filepicker return(output); }
private static string GetSummary(HtmlHelper htmlHelper) { var viewContext = htmlHelper.ViewContext; System.Web.Mvc.FormContext formContext = viewContext.ClientValidationEnabled ? viewContext.FormContext : null; if (htmlHelper.ViewData.ModelState.IsValid && formContext == null) { return(null); } var modelState = GetModelStateList(htmlHelper); StringBuilder listBuilder = new StringBuilder(); foreach (var state in modelState) { foreach (var error in state.Value.Errors) { string message = error.ErrorMessage; if (!string.IsNullOrWhiteSpace(message)) { listBuilder.Append("<li>"); string key = state.Key; if (!string.IsNullOrWhiteSpace(key) && !message.Contains(key)) { int lastDot = key.LastIndexOf('.'); if (lastDot != -1) { string suffix = key.Substring(lastDot + 1); if (message.Contains(suffix)) { key = key.Substring(0, lastDot); } } listBuilder.Append("<strong>"); listBuilder.Append(key.Replace('.', ' ').ToWords(true)); listBuilder.Append("</strong> "); } listBuilder.Append(message); listBuilder.AppendLine("</li>"); } } } if (listBuilder.Length == 0) { if (viewContext.UnobtrusiveJavaScriptEnabled || formContext == null) { return(null); } listBuilder.AppendLine("<li style=\"display:none\"></li>"); } var listTag = new HtmlTagBuilder("ul") { InnerHtml = listBuilder.ToString() }; var divBuilder = new HtmlTagBuilder("div"); divBuilder.AddCssClass(htmlHelper.ViewData.ModelState.IsValid ? HtmlHelper.ValidationSummaryValidCssClassName : HtmlHelper.ValidationSummaryCssClassName); divBuilder.AddCssClass("alert alert-danger fade in"); if (formContext != null) { if (viewContext.UnobtrusiveJavaScriptEnabled) { divBuilder.MergeAttribute("data-valmsg-summary", "true"); } else { divBuilder.GenerateId("validationSummary"); formContext.ValidationSummaryId = divBuilder.Attributes["id"]; formContext.ReplaceValidationSummary = true; } } divBuilder.InnerHtml = "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>" + listTag.ToString(); return(divBuilder.ToString()); }