private static IEnumerable <SelectListItem> GetItemsForBvDropDownList(BvSelectList selectList) { List <SelectListItem> items = new SelectList(selectList.items, selectList.dataValueField, selectList.dataTextField, selectList.selectedValue).ToList(); if (selectList.selectedValue != null) { SelectListItem item = items.Where(x => x.Value == ((IObject)selectList.selectedValue).Key.ToString()).SingleOrDefault(); item.Selected = true; } return(items); }
public static MvcHtmlString BvDropDownList(this HtmlHelper htmlHelper, IObject obj, string bindToProp, string clientOnChange = null) { Dictionary <string, object> htmlAttributes = GetHtmlAttributes(obj, bindToProp); htmlAttributes.Add("onChange", !string.IsNullOrEmpty(clientOnChange) ? clientOnChange : string.Format("new function () {{ ModelFieldChangedCombobox('{0}'); }}", obj.ObjectIdent + bindToProp)); BvSelectList selectList = obj.GetList(bindToProp); MvcHtmlString dropDownList; if (selectList != null) { IEnumerable <SelectListItem> items = GetItemsForBvDropDownList(selectList); dropDownList = htmlHelper.DropDownList(obj.ObjectIdent + bindToProp, items, htmlAttributes); } else { dropDownList = htmlHelper.DropDownList(obj.ObjectIdent + bindToProp); } return(dropDownList); }