Пример #1
0
        public static MvcHtmlString ExtEditorBasicFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, IEnumerable <TValue> > > expression, bool readOnly = false, object htmlAttributes = null)
        {
            var html = htmlAttributes == null
                                                        ? new RouteValueDictionary()
                                                        : new RouteValueDictionary(htmlAttributes);

            html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            html = HtmlAttributeHelper.AddTextAreaStyle(html);

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextAreaFor(expression, html).ToString());


            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>");
            if (readOnly)
            {
                stringBuilder.AppendLine(string.Format("CKEDITOR.replace('{0}', {{ customConfig: 'config-basic.js', readOnly: true }})", controlId));
            }
            else
            {
                stringBuilder.AppendLine(string.Format("CKEDITOR.replace('{0}', {{ customConfig: 'config-basic.js' }})", controlId));
            }

            stringBuilder.AppendLine("</script>");

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, stringBuilder.ToString(), expression));
        }
Пример #2
0
        public static MvcHtmlString ExtTextBoxAddOnForEnable <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                              Expression <Func <TModel, TValue> > expression, CustomControlConstants.AddOn addOn, string target = null, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }
            //html.Add("readonly", true);
            var textBox = "<div class='input-group'>";

            textBox += htmlHelper.TextBoxFor(expression, html).ToString();
            if (addOn == CustomControlConstants.AddOn.Search)
            {
                textBox +=
                    "<span class='input-group-addon' style='cursor: pointer' data-toggle='modal' data-target='" + target + "'><i class='fa fa-search'></i></span>";
            }
            textBox += "</div>";
            if (!string.IsNullOrEmpty(format))
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         htmlHelper.TextBoxFor(expression, format, html).ToString(), expression));
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     textBox, expression));
        }
Пример #3
0
        public static MvcHtmlString ExtSingleSuggestionFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                            Expression <Func <TModel, TValue> > expression, SingleSuggestionOption option, object htmlAttributes = null)
        {
            var html = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);
            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            stringBuilder.AppendLine(string.Format("$('#{0}').tokenInput('{1}',{{", controlId, option.SearchUrl));
            stringBuilder.AppendLine("theme: 'facebook',");
            stringBuilder.AppendLine("tokenLimit: 1,");
            stringBuilder.AppendLine("method: 'POST',");
            stringBuilder.AppendLine(string.Format("required: {0},", expression.IsRequired().ToString().ToLower()));
            stringBuilder.AppendLine("queryParam: 'query',");
            stringBuilder.AppendLine("tokenValue: 'Id',");
            stringBuilder.AppendLine("propertyToSearch: 'Name',");
            stringBuilder.AppendLine("minChars: 0,");
            if (option.DefaultValue != null)
            {
                stringBuilder.AppendLine(string.Format("prePopulate: [{0}],", Newtonsoft.Json.JsonConvert.SerializeObject(option.DefaultValue)));
            }

            if (!string.IsNullOrEmpty(option.OnAdd))
            {
                stringBuilder.AppendLine(string.Format("onAdd: {0},", option.OnAdd));
            }

            if (!string.IsNullOrEmpty(option.OnDelete))
            {
                stringBuilder.AppendLine(string.Format("onDelete: {0},", option.OnDelete));
            }

            if (!string.IsNullOrEmpty(option.AdditionalParam))
            {
                stringBuilder.AppendLine(string.Format("additionalParam: {0},", option.AdditionalParam));
            }
            if (option.LocalData != null)
            {
                stringBuilder.AppendLine(string.Format("local_data: {0},", Newtonsoft.Json.JsonConvert.SerializeObject(option.LocalData)));
            }
            if (option.CreateNew.HasValue)
            {
                stringBuilder.AppendLine(string.Format("createNew: {0},", option.CreateNew.Value.ToString().ToLower()));
            }

            if (!string.IsNullOrEmpty(option.OnResult))
            {
                stringBuilder.AppendLine(string.Format("onResult: {0},", option.OnResult));
            }

            stringBuilder.AppendLine("});});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Пример #4
0
        public static MvcHtmlString ExtDropDownListFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                        Expression <Func <TModel, TValue> > expression, IEnumerable <SelectListItem> selectList,
                                                                        string optionLabel = null, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.DropDownListFor(expression, selectList, optionLabel, html).ToString(), expression));
        }
Пример #5
0
        private static MvcHtmlString ExtCheckBoxListSingleColumnFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                                     Expression <Func <TModel, IEnumerable <TValue> > > expression, IEnumerable <SelectListItem> values,
                                                                                     IEnumerable <TValue> selectedIds, object htmlAttributes = null)
        {
            var isDisabled = false;
            var html       = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);

            if (html["disabled"] != null && html["disabled"].ToString() == "disabled")
            {
                isDisabled = true;
            }

            var selectedValues = selectedIds.Select(x => x.ToString()).ToList();
            var variableName   = ExpressionHelper.GetExpressionText(expression);
            var stringBuilder  = new StringBuilder();

            foreach (var selectListItem in values)
            {
                var itemName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(variableName);
                var itemId   = itemName + CustomControlHelper.GetControlCount(itemName);

                var divBuilder = new TagBuilder("div");
                divBuilder.AddCssClass("checkbox");
                if (isDisabled)
                {
                    divBuilder.AddCssClass("disabled");
                }

                var labelBuilder = new TagBuilder("label");
                labelBuilder.MergeAttribute("for", itemId);

                var inputBuilder = new TagBuilder("input");
                if (selectedValues.Contains(selectListItem.Value))
                {
                    inputBuilder.MergeAttribute("checked", "checked");
                }
                if (isDisabled)
                {
                    inputBuilder.MergeAttribute("disabled", "disabled");
                }
                inputBuilder.MergeAttribute("id", itemId);
                inputBuilder.MergeAttribute("name", itemName);
                inputBuilder.MergeAttribute("type", "checkbox");
                inputBuilder.MergeAttribute("value", selectListItem.Value);

                var labelInner = inputBuilder + selectListItem.Text;
                labelBuilder.InnerHtml = labelInner;
                divBuilder.InnerHtml   = labelBuilder.ToString();
                stringBuilder.Append(divBuilder);
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, stringBuilder.ToString(), expression));
        }
Пример #6
0
        public static MvcHtmlString ExtTextAreaFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                    Expression <Func <TModel, TValue> > expression, object htmlAttributes = null)
        {
            var html = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);

            html = HtmlAttributeHelper.AddTextAreaStyle(html);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.TextAreaFor(expression, html).ToString(), expression));
        }
Пример #7
0
        public static MvcHtmlString ExtTextBoxNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                         Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }
            var stringBuilder = new StringBuilder();

            if (!string.IsNullOrEmpty(format))
            {
                stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, format, html).ToString());
            }
            else
            {
                stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            }

            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            stringBuilder.AppendLine("$('#" + controlId + "').keypress(function(event) {");
            // stringBuilder.AppendLine("var charCode = (event.which) ? event.which : event.keyCode;");
            stringBuilder.AppendLine("if (event.which != 8 && event.which != 0 && (event.which < 48 || event.which > 57)) {");
            stringBuilder.AppendLine("return false;");
            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine("else {");
            stringBuilder.AppendLine("return true;");
            stringBuilder.AppendLine("};");
            stringBuilder.AppendLine("});");
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Пример #8
0
        public static MvcHtmlString ExtCheckBoxFor <TModel>(this HtmlHelper <TModel> htmlHelper,
                                                            Expression <Func <TModel, bool> > expression, object htmlAttributes = null, string checkboxText = null)
        {
            var labelBuilder = new TagBuilder("label")
            {
                InnerHtml = htmlHelper.CheckBoxFor(expression, htmlAttributes).ToString()
            };

            if (!string.IsNullOrEmpty(checkboxText))
            {
                labelBuilder.InnerHtml          += checkboxText;
                labelBuilder.Attributes["style"] = "font-weight: bold, margin-left:10px";
            }
            var divBuilder = new TagBuilder("div");

            divBuilder.AddCssClass("checkbox");
            divBuilder.InnerHtml = labelBuilder.ToString();

            var stringBuilder = new StringBuilder();

            stringBuilder.Append(divBuilder);

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, stringBuilder.ToString(), expression));
        }
Пример #9
0
        public static MvcHtmlString ExtTextBoxFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                   Expression <Func <TModel, TValue> > expression, object htmlAttributes = null, string format = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }

            if (!string.IsNullOrEmpty(format))
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         htmlHelper.TextBoxFor(expression, format, html).ToString(), expression));
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     htmlHelper.TextBoxFor(expression, html).ToString(), expression));
        }
Пример #10
0
        public static MvcHtmlString ExtNumberAddOnFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, TValue> > expression, CustomControlConstants.AddOn addOn, String textAddOn = null, NumberOption option = null, object htmlAttributes = null)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<div class='input-group padding-right-8'>");
            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            switch (addOn)
            {
            case CustomControlConstants.AddOn.Text:
                stringBuilder.AppendLine(" <span class='input-group-addon'>" + textAddOn + "</span>");
                break;
            }
            stringBuilder.AppendLine("</div >");
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ','",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add(string.Format("vMin: '{0}'", option.Min.Value));
                }
                if (option.Max.HasValue)
                {
                    options.Add(string.Format("vMax: '{0}'", option.Max.Value));
                }
                else
                {
                    options.Add(string.Format("vMax: '{0}'", 9999999));
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add(string.Format("aSign: '{0}'", option.ASign));
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add(string.Format("pSign: '{0}'", option.PSign));
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add(string.Format("mDec : {0}", option.NumberOfDecimal.Value));
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#{0}').autoNumeric('init', {{{1}}});", controlId, optionsStr));
            stringBuilder.AppendLine("});</script>");
            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                     stringBuilder.ToString(), expression));
        }
Пример #11
0
        public static MvcHtmlString ExtCheckBoxListFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                        Expression <Func <TModel, IEnumerable <TValue> > > expression, IEnumerable <SelectListItem> values,
                                                                        IEnumerable <TValue> selectedIds, int columnNumber = 1, object htmlAttributes = null)
        {
            if (columnNumber <= 1)
            {
                return(htmlHelper.ExtCheckBoxListSingleColumnFor(expression, values, selectedIds, htmlAttributes));
            }

            var isDisabled = false;
            var html       = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);

            if (html["disabled"] != null && html["disabled"].ToString() == "disabled")
            {
                isDisabled = true;
            }

            var variableName = ExpressionHelper.GetExpressionText(expression);
            var itemName     = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(variableName);

            var selectedValues  = selectedIds.Select(x => x.ToString()).ToList();
            var selectListItems = values.ToList();
            var rowNumber       = selectListItems.Count / columnNumber + 1;

            var tableBuilder = new TagBuilder("table");

            for (var rowIndex = 0; rowIndex < rowNumber; rowIndex++)
            {
                var trBuilder = new TagBuilder("tr");
                for (var columnIndex = 0; columnIndex < columnNumber; columnIndex++)
                {
                    var itemIndex = rowIndex * columnNumber + columnIndex;
                    if (itemIndex >= selectListItems.Count)
                    {
                        break;
                    }

                    var itemId = itemName + CustomControlHelper.GetControlCount(itemName);

                    var inputBuilder = new TagBuilder("input");
                    inputBuilder.MergeAttribute("id", itemId);
                    inputBuilder.MergeAttribute("name", itemName);
                    inputBuilder.MergeAttribute("type", "checkbox");
                    inputBuilder.MergeAttribute("value", selectListItems[itemIndex].Value);
                    if (selectedValues.Contains(selectListItems[itemIndex].Value))
                    {
                        inputBuilder.MergeAttribute("checked", "checked");
                    }
                    if (isDisabled)
                    {
                        inputBuilder.MergeAttribute("disabled", "disabled");
                    }

                    var labelInner = inputBuilder + selectListItems[itemIndex].Text;

                    var labelBuilder = new TagBuilder("label");
                    labelBuilder.MergeAttribute("for", itemId);
                    labelBuilder.InnerHtml = labelInner;

                    var divBuilder = new TagBuilder("div");
                    //divBuilder.AddCssClass("checkbox");
                    if (isDisabled)
                    {
                        divBuilder.AddCssClass("disabled");
                    }
                    divBuilder.InnerHtml = labelBuilder.ToString();

                    var tdBuilder = new TagBuilder("td")
                    {
                        InnerHtml = divBuilder.ToString()
                    };
                    trBuilder.InnerHtml += tdBuilder.ToString();
                }

                tableBuilder.InnerHtml += trBuilder.ToString();
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, tableBuilder.ToString(), expression));
        }
Пример #12
0
        public static MvcHtmlString ExtNumberFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                  Expression <Func <TModel, TValue> > expression, NumberOption option = null, object htmlAttributes = null, bool showmessage = true)
        {
            var html      = HtmlAttributeHelper.AddDefaultClass(htmlAttributes);
            var maxLength = expression.MaxLength();

            if (maxLength != 0)
            {
                html = HtmlAttributeHelper.AddMaxLength(html, maxLength);
            }
            else
            {
                html = HtmlAttributeHelper.AddMaxLength(html, 255);
            }

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(htmlHelper.TextBoxFor(expression, html).ToString());
            var controlId = HtmlAttributeHelper.GetControlIdFromExpression(expression);

            stringBuilder.AppendLine("<script>$(function(){");
            var options = new List <string>()
            {
                "aSep: ','",
                "aDec: '.'"
            };

            if (option != null)
            {
                if (option.Min.HasValue)
                {
                    options.Add(string.Format("vMin: '{0}'", option.Min.Value));
                }
                if (option.Max.HasValue)
                {
                    options.Add(string.Format("vMax: '{0}'", option.Max.Value));
                }
                else
                {
                    options.Add(string.Format("vMax: '{0}'", 9999999));
                }
                if (!string.IsNullOrEmpty(option.ASign))
                {
                    options.Add(string.Format("aSign: '{0}'", option.ASign));
                }
                if (!string.IsNullOrEmpty(option.PSign))
                {
                    options.Add(string.Format("pSign: '{0}'", option.PSign));
                }
                if (option.NumberOfDecimal.HasValue)
                {
                    options.Add(string.Format("mDec : {0}", option.NumberOfDecimal.Value));
                }
            }
            var optionsStr = string.Join(", ", options);

            stringBuilder.AppendLine(string.Format("$('#{0}').autoNumeric('init', {{{1}}});", controlId, optionsStr));
            stringBuilder.AppendLine("});</script>");
            if (showmessage)
            {
                return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper,
                                                                         stringBuilder.ToString(), expression));
            }
            else
            {
                return(new MvcHtmlString(stringBuilder.ToString()));
            }
        }
Пример #13
0
        public static MvcHtmlString ExtRadioButtonFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, TValue> > expression, IEnumerable <SelectListItem> values,
                                                                       object htmlAttributes = null, bool isInline = false, int size = 1)
        {
            var isDisabled = false;
            var html       = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);

            if (html["disabled"] != null && html["disabled"].ToString() == "disabled")
            {
                isDisabled = true;
            }

            var stringBuilder = new StringBuilder();

            if (isInline)
            {
                foreach (var selectListItem in values)
                {
                    if (selectListItem.Selected)
                    {
                        html.Add("checked", "true");
                    }
                    else
                    {
                        html.Remove("checked");
                    }
                    var input = htmlHelper.RadioButtonFor(expression, selectListItem.Value, html);
                    var label = selectListItem.Text;

                    var divBuilder = new TagBuilder("div");
                    if (isDisabled)
                    {
                        divBuilder.AddCssClass("disabled");
                    }

                    divBuilder.AddCssClass("col-xs-" + size);
                    divBuilder.InnerHtml = input + " " + label;

                    stringBuilder.Append(divBuilder);
                }
            }
            else
            {
                foreach (var selectListItem in values)
                {
                    if (selectListItem.Selected)
                    {
                        html.Add("checked", "true");
                    }
                    else
                    {
                        html.Remove("checked");
                    }
                    var input = htmlHelper.RadioButtonFor(expression, selectListItem.Value, html);
                    var label = selectListItem.Text;

                    var labelBuilder = new TagBuilder("label")
                    {
                        InnerHtml = input + label
                    };

                    var divBuilder = new TagBuilder("div");
                    divBuilder.AddCssClass("radio");
                    if (isDisabled)
                    {
                        divBuilder.AddCssClass("disabled");
                    }

                    divBuilder.InnerHtml = labelBuilder.ToString();

                    stringBuilder.Append(divBuilder);
                }
            }

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, stringBuilder.ToString(), expression));
        }
Пример #14
0
        public static MvcHtmlString ExtMultiSelectFor <TModel, TValue>(this HtmlHelper <TModel> htmlHelper,
                                                                       Expression <Func <TModel, IEnumerable <TValue> > > expression, IEnumerable <SelectListItem> values,
                                                                       IEnumerable <TValue> selectedIds, string controlId, object htmlAttributes = null)
        {
            var isDisabled = false;
            var html       = htmlAttributes == null
                ? new RouteValueDictionary()
                : new RouteValueDictionary(htmlAttributes);

            if (html["disabled"] != null && html["disabled"].ToString() == "disabled")
            {
                isDisabled = true;
            }

            var selectListItems = values.ToList();

            var leftListBuilder = new TagBuilder("select");

            leftListBuilder.AddCssClass("form-control");
            leftListBuilder.MergeAttribute("name", "leftList" + CustomControlHelper.GetControlCount("leftList"));
            leftListBuilder.MergeAttribute("id", controlId + "_from");
            leftListBuilder.MergeAttribute("size", "8");
            leftListBuilder.MergeAttribute("multiple", "multiple");
            if (isDisabled)
            {
                leftListBuilder.MergeAttribute("disabled", "disabled");
            }

            foreach (var selectListItem in selectListItems)
            {
                var optionBuilder = new TagBuilder("option");
                optionBuilder.MergeAttribute("value", selectListItem.Value);
                optionBuilder.SetInnerText(selectListItem.Text);
                leftListBuilder.InnerHtml += optionBuilder.ToString();
            }

            var leftColumnBuilder = new TagBuilder("div");

            leftColumnBuilder.AddCssClass("col-xs-5");
            leftColumnBuilder.InnerHtml = leftListBuilder.ToString();

            var rightAllIconBuilder = new TagBuilder("i");

            rightAllIconBuilder.AddCssClass("glyphicon");
            rightAllIconBuilder.AddCssClass("glyphicon-forward");

            var rightAllButtonBuilder = new TagBuilder("button");

            rightAllButtonBuilder.MergeAttribute("type", "button");
            rightAllButtonBuilder.MergeAttribute("id", controlId + "_rightAll");
            rightAllButtonBuilder.AddCssClass("btn");
            rightAllButtonBuilder.AddCssClass("btn-block");
            rightAllButtonBuilder.InnerHtml = rightAllIconBuilder.ToString();

            var rightSelectedIconBuilder = new TagBuilder("i");

            rightSelectedIconBuilder.AddCssClass("glyphicon");
            rightSelectedIconBuilder.AddCssClass("glyphicon-chevron-right");

            var rightSelectedButtonBuilder = new TagBuilder("button");

            rightSelectedButtonBuilder.MergeAttribute("type", "button");
            rightSelectedButtonBuilder.MergeAttribute("id", controlId + "_rightSelected");
            rightSelectedButtonBuilder.AddCssClass("btn");
            rightSelectedButtonBuilder.AddCssClass("btn-block");
            rightSelectedButtonBuilder.InnerHtml = rightSelectedIconBuilder.ToString();

            var leftSelectedIconBuilder = new TagBuilder("i");

            leftSelectedIconBuilder.AddCssClass("glyphicon");
            leftSelectedIconBuilder.AddCssClass("glyphicon-chevron-left");

            var leftSelectedButtonBuilder = new TagBuilder("button");

            leftSelectedButtonBuilder.MergeAttribute("type", "button");
            leftSelectedButtonBuilder.MergeAttribute("id", controlId + "_leftSelected");
            leftSelectedButtonBuilder.AddCssClass("btn");
            leftSelectedButtonBuilder.AddCssClass("btn-block");
            leftSelectedButtonBuilder.InnerHtml = leftSelectedIconBuilder.ToString();

            var leftAllIconBuilder = new TagBuilder("i");

            leftAllIconBuilder.AddCssClass("glyphicon");
            leftAllIconBuilder.AddCssClass("glyphicon-backward");

            var leftAllButtonBuilder = new TagBuilder("button");

            leftAllButtonBuilder.MergeAttribute("type", "button");
            leftAllButtonBuilder.MergeAttribute("id", controlId + "_leftAll");
            leftAllButtonBuilder.AddCssClass("btn");
            leftAllButtonBuilder.AddCssClass("btn-block");
            leftAllButtonBuilder.InnerHtml = leftAllIconBuilder.ToString();

            if (isDisabled)
            {
                rightAllButtonBuilder.AddCssClass("disabled");
                rightSelectedButtonBuilder.AddCssClass("disabled");
                leftSelectedButtonBuilder.AddCssClass("disabled");
                leftAllButtonBuilder.AddCssClass("disabled");
                rightAllButtonBuilder.MergeAttribute("disabled", "disabled");
                rightSelectedButtonBuilder.MergeAttribute("disabled", "disabled");
                leftSelectedButtonBuilder.MergeAttribute("disabled", "disabled");
                leftAllButtonBuilder.MergeAttribute("disabled", "disabled");
            }

            var middleColumnBuilder = new TagBuilder("div");

            middleColumnBuilder.AddCssClass("col-xs-2");
            middleColumnBuilder.InnerHtml += rightAllButtonBuilder.ToString();
            middleColumnBuilder.InnerHtml += rightSelectedButtonBuilder.ToString();
            middleColumnBuilder.InnerHtml += leftSelectedButtonBuilder.ToString();
            middleColumnBuilder.InnerHtml += leftAllButtonBuilder.ToString();

            var variableName = ExpressionHelper.GetExpressionText(expression);
            var itemName     = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(variableName);

            var rightListBuilder = new TagBuilder("select");

            rightListBuilder.AddCssClass("form-control");
            rightListBuilder.MergeAttribute("name", itemName);
            rightListBuilder.MergeAttribute("id", controlId + "_to");
            rightListBuilder.MergeAttribute("size", "8");
            rightListBuilder.MergeAttribute("multiple", "multiple");

            if (isDisabled)
            {
                rightListBuilder.MergeAttribute("disabled", "disabled");
            }

            foreach (var selectedId in selectedIds)
            {
                var selectedItem = selectListItems.FirstOrDefault(x => x.Value == selectedId.ToString());
                if (selectedItem == null)
                {
                    continue;
                }

                var optionBuilder = new TagBuilder("option");
                optionBuilder.MergeAttribute("value", selectedItem.Value);
                optionBuilder.SetInnerText(selectedItem.Text);
                rightListBuilder.InnerHtml += optionBuilder.ToString();
            }

            var rightColumnBuilder = new TagBuilder("div");

            rightColumnBuilder.AddCssClass("col-xs-5");
            rightColumnBuilder.InnerHtml = rightListBuilder.ToString();

            var rowBuilder = new TagBuilder("div");

            rowBuilder.AddCssClass("row");
            rowBuilder.InnerHtml  = leftColumnBuilder.ToString();
            rowBuilder.InnerHtml += middleColumnBuilder.ToString();
            rowBuilder.InnerHtml += rightColumnBuilder.ToString();

            var scriptBuilder = new TagBuilder("script");

            scriptBuilder.MergeAttribute("type", "text/javascript");
            scriptBuilder.InnerHtml = "jQuery(document).ready(function($) { $('#" + controlId + "').multiselect(); });";

            var stringBuilder = new StringBuilder();

            stringBuilder.AppendLine(rowBuilder.ToString());
            stringBuilder.AppendLine(scriptBuilder.ToString());

            return(CustomControlHelper.GenerateWithValidationMessage(htmlHelper, stringBuilder.ToString(), expression));
        }