CreateSelectList

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()
            });
        }
Example:
productList.CreateSelectList(x => x.Id, x => x.Name)

Description

Convert any list of objects to a select list

Details

Double click on the code to select all.

 

;