public static List <SelectListItem> ToSelectListItems(this IEnumerable <string> values, List <string> selectedValues = null, bool addDefault = false) { Check.Null(values, "values"); var query = selectedValues == null || !selectedValues.Any() ? values.Select(x => DDLHelper.GetSelectListItem(x)) : values.Select(x => DDLHelper.GetMarkedSelectListItem(x, selectedValues)); return(addDefault ? query.ToDefaultPrependedList() : query.AsList()); }
public static List <SelectListItem> ToSelectListItems(this IEnumerable <string> values, string selectedValue = null, bool addDefault = false) { Check.Null(values, "values"); var query = string.IsNullOrWhiteSpace(selectedValue) ? values.Select(x => DDLHelper.GetSelectListItem(x)) : values.Select(x => DDLHelper.GetMarkedSelectListItem(x, selectedValue)); return(addDefault ? query.ToDefaultPrependedList() : query.AsList()); }