ExtensionMethod.NET Home of 877 C#, Visual Basic, F# and Javascript extension methods


Convert any list of objects to a select list


public static IEnumerable<SelectListItem> CreateSelectList<T>(this List<T> entities, Func<T, object> value, Func<T, object> text)
    return entities.Select(x => new SelectListItem
        Value = value(x).ToString(),
        Text = text(x).ToString()


productList.CreateSelectList(x => x.Id, x => x.Name)

Author: Djordje Djukic

Submitted on: 8 jul. 2016

Language: C#

Type: IEnumerable<SelectListItem>

Views: 3469