public static MvcHtmlString BsSelect2DropDownFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, SelectList selectList, string icon = null, Select2Option option = null, ComponentDirection?dir = null, int lable_col = 2, int editor_col = 4) { string displayName = null; SetVariables(html, expression, ref displayName, out string style, out string dirName, out string label, out string validator, out object value, lable_col, dir); if (option == null) { option = new Select2Option(); } var editor = html.Select2DropDownFor(expression, selectList, option: option); var result = SetTemplate(label, icon, editor_col, validator, editor.ToHtmlString(), dirName); return(MvcHtmlString.Create(result)); }
public static MvcHtmlString BsSelect2ListBoxFor <TModel, TValue, T1, T2>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Dictionary <T1, T2> source, string defaultValue = null, string icon = null, Select2Option option = null, ComponentDirection?dir = null, int lable_col = 2, int editor_col = 4) { string displayName = null; SetVariables(html, expression, ref displayName, out string style, out string dirName, out string label, out string validator, out object value, lable_col, dir); var selectList = new SelectList(source, "Key", "Value", value); var editor = html.Select2ListBoxFor(expression, source, defaultValue, option); var result = SetTemplate(label, icon, editor_col, validator, editor.ToHtmlString(), dirName); return(MvcHtmlString.Create(result)); }
public static MvcHtmlString Select2DropDownFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, SelectList selectList, string defaultValue = null, object htmlAttribute = null, Select2Option option = null) { option = option ?? new Select2Option(); var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); var htmlFieldName = ExpressionHelper.GetExpressionText(expression); var id = html.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName); var displayName = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last(); var value = metadata.Model; var items = selectList.Cast <SelectListItem>().ToList(); if (defaultValue.HasValue()) { items.Insert(0, new SelectListItem { Value = "", Text = defaultValue }); } var attributes = ComponentUtility.MergeAttributes(htmlAttribute, new { @class = "form-control", placeholder = displayName, style = "width: 100%" }); var editor = html.DropDownListFor(expression, items, attributes); var result = editor.ToHtmlString() + html.StyleFileSingle(@"<link href=""" + ComponentUtility.GetWebResourceUrl(select2_css) + @""" rel=""stylesheet"" />").ToHtmlString() + html.StyleFileSingle(@"<link href=""" + ComponentUtility.GetWebResourceUrl(select2_custom_css) + @""" rel=""stylesheet"" />").ToHtmlString() + (option.Attributes["language"] == null ? "" : html.ScriptFileSingle(@"<script src=""" + ComponentUtility.GetWebResourceUrl(string.Format("Savosh.Component.Select2.i18n.{0}.js", option.Attributes["language"].ToString().Trim('\''))) + @"""></script>").ToHtmlString()) + html.ScriptFileSingle(@" <script src=""" + ComponentUtility.GetWebResourceUrl(select2_js) + @"""></script>").ToHtmlString() + html.Script(@" <script> $(function(){ $(""#" + id + @""").select2(" + option.RenderOptions() + @").change(function () { $(this).valid(); }); }); </script>").ToHtmlString(); return(MvcHtmlString.Create(result)); }
public static MvcHtmlString Select2DropDown <T1, T2>(this HtmlHelper html, string name, T1 value, Dictionary <T1, T2> source, string defaultValue = null, object htmlAttribute = null, Select2Option option = null) { option = option ?? new Select2Option(); var id = html.ViewData.TemplateInfo.GetFullHtmlFieldId(name); var selectList = new SelectList(source, "Key", "Value", value); var items = selectList.Cast <SelectListItem>().ToList(); //if (defaultValue.HasValue()) // items.Insert(0, new SelectListItem { Value = null, Text = defaultValue }); var attributes = ComponentUtility.MergeAttributes(htmlAttribute, new { @class = "form-control", style = "width: 100%" }); var editor = html.DropDownList(name, items, defaultValue, attributes); var result = editor.ToHtmlString() + html.StyleFileSingle(@"<link href=""" + ComponentUtility.GetWebResourceUrl(select2_css) + @""" rel=""stylesheet"" />").ToHtmlString() + html.StyleFileSingle(@"<link href=""" + ComponentUtility.GetWebResourceUrl(select2_custom_css) + @""" rel=""stylesheet"" />").ToHtmlString() + (option.Attributes["language"] == null ? "" : html.ScriptFileSingle(@"<script src=""" + ComponentUtility.GetWebResourceUrl(string.Format("Savosh.Component.Select2.i18n.{0}.js", option.Attributes["language"].ToString().Trim('\''))) + @"""></script>").ToHtmlString()) + html.ScriptFileSingle(@" <script src=""" + ComponentUtility.GetWebResourceUrl(select2_js) + @"""></script>").ToHtmlString() + html.Script(@" <script> $(function(){ $(""#" + id + @""").select2(" + option.RenderOptions() + @").change(function () { $(this).valid(); }); }); </script>").ToHtmlString(); return(MvcHtmlString.Create(result)); }