public IHtmlString WithFilterButton(bool inSeparateRow = false, string filterFunction = "RefreshGrid", bool useUnobtrusive = false, string filterButtonLabel = null) { var filterButton = useUnobtrusive ? htmlHelper.UnobtrusiveFilterButton(filterButtonLabel).ToHtmlString() : htmlHelper.FilterButton(string.Format("{0}()", filterFunction), filterButtonLabel).ToHtmlString(); var filterButtonBuilder = new FluentTagBuilder("td").AddToInnerHtml(filterButton); if (inSeparateRow) { if (lastRowBuilder != null) { fluentTagBuilder.AddToInnerHtml(lastRowBuilder.AddToInnerHtml(emptyCellBuilder.ToString())); } var filterRow = new FluentTagBuilder("tr"); filterRow .AddToInnerHtml(emptyCellBuilder.ToString()) .AddToInnerHtml(filterButtonBuilder.AddAttribute("style", "text-align:right").ToString()) .AddToInnerHtml(emptyCellBuilder.ToString()); fluentTagBuilder.AddToInnerHtml(filterRow); return(this); } if (lastRowBuilder != null) { lastRowBuilder.AddToInnerHtml(filterButtonBuilder.ToString()); fluentTagBuilder.AddToInnerHtml(lastRowBuilder); return(this); } return(this); }
private FluentTagBuilder BuildRowWithLabel <TValue>(Expression <Func <TModel, TValue> > expression, string editorString, bool visible = true, bool isDropDown = false) { int editorRightPadding = isDropDown ? 0 : 4; if (editorString.Contains("kendo")) { editorString = editorString.Replace("198px;", "200px;"); } var fieldLabelTd = new FluentTagBuilder("td") .AddToInnerHtml(htmlHelper.LocalizedLabelFor(expression).ToString()) .AddCssClass("field-label"); if (fieldLabelWidth.HasValue) { fieldLabelTd.AddAttribute("style", string.Format("width: {0}px", fieldLabelWidth)); } var fieldEditorTd = new FluentTagBuilder("td") .AddToInnerHtml(editorString) .AddCssClass("field-input"); if (fieldEditorWidth.HasValue) { fieldEditorTd.AddAttribute("style", string.Format("width: {0}px; padding-right: {1}px", fieldEditorWidth, editorRightPadding)); } else { fieldEditorTd.AddAttribute("style", string.Format("padding-right: {0}px", editorRightPadding)); } var editorRow = new FluentTagBuilder("tr") .AddToInnerHtml(fieldLabelTd) .AddToInnerHtml(fieldEditorTd); if (!visible) { editorRow.AddAttribute("style", "display: none"); } return(editorRow); }
private void BuildEditor <TValue>(Expression <Func <TModel, TValue> > expression, bool requiredField, string editorString, string validationMessageHtml, string editorPostfix = null, bool visible = true, string customLabel = null, bool isDropDown = false) { int editorRightPadding = isDropDown ? 0 : 5; if (editorString.Contains("kendo")) { editorString = editorString.Replace("198px;", "200px;"); } var fieldLabelTd = new FluentTagBuilder("td") .AddToInnerHtml(customLabel.HasText() ? customLabel : htmlHelper.LocalizedLabelFor(expression).ToString()) .AddCssClass("field-label"); if (fieldLabelWidth.HasValue) { fieldLabelTd.AddAttribute("style", string.Format("min-width: {0}px; max-width: {0}px", fieldLabelWidth)); } if (requiredField) { fieldLabelTd.AddCssClass("field-required"); } var fieldEditorTd = new FluentTagBuilder("td") .AddToInnerHtml(editorString) .AddCssClass("field-input"); if (fieldEditorWidth.HasValue) { fieldEditorTd.AddAttribute("style", string.Format("width: {0}px; padding-right: {1}px", fieldEditorWidth, editorRightPadding)); } else { fieldEditorTd.AddAttribute("style", string.Format("padding-right: {0}px", editorRightPadding)); } if (editorPostfix != null) { fieldEditorTd.AddToInnerHtml(editorPostfix); } string modelName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression)); ModelState modelState = htmlHelper.ViewData.ModelState[modelName]; ModelErrorCollection modelErrors = (modelState == null) ? null : modelState.Errors; var errorTd = new FluentTagBuilder("td").AddAttribute("style", "width: 24px"); if (modelErrors != null && modelErrors.Count > 0) { errorTd.AddToInnerHtml(new FluentTagBuilder("img") .AddAttribute("src", htmlHelper.ToUrlHelper().Content("~/Content/Images/infoerror.gif")) .AddAttribute("data-property", ExpressionHelper.GetExpressionText(expression)) .AddCssClass("error-image") .ToString(TagRenderMode.SelfClosing)); errorTd .AddToInnerHtml( new FluentTagBuilder("div") .AddCssClass("error-message-div") .AddAttribute("data-property", ExpressionHelper.GetExpressionText(expression)) .AddAttribute("data-title", (string)HtmlHelperExtensions.HtmlHelperExtensions.Localize(expression)) .AddToInnerHtml(validationMessageHtml)); } var editorRow = new FluentTagBuilder("tr") .AddToInnerHtml(fieldLabelTd) .AddToInnerHtml(fieldEditorTd) .AddToInnerHtml(errorTd); if (!visible) { editorRow.AddAttribute("style", "display: none"); } fluentTagBuilder.AddToInnerHtml(editorRow); }