ToSelectList IEnumerable<TSource>

.ToSelectList()

Takes a list of and convert it into a SelectList.

Method

public static SelectList<TSource, TResult> ToSelectList(this IEnumerable<TSource> source, Func<TSource, TResult> selector, bool firstEmpty = true, string emptyValue = "", bool emptyGuid = false, bool other = false)
IEnumerable<TSource> source

A list to convert into a SelectList.

Func<TSource, TResult> selector

A function passed through to specify which properties in the list to use for the SelectList.

bool firstEmpty
Default: true

Make the first item in the SelectList an empty or blank item.

string emptyValue
Default: true

If the firstEmpty is true then set this value as the empty value.

bool emptyGuid
Default: true

If the firstEmpty is true then set this value as the Empty Guid {00000000-0000-0000-0000-000000000000} value.

Example

C#
ViewBag.List = db.MySpGet().ToSelectList(x => SiUtil.SelectListItem(x.MyFieldId, x.MyField));