src/MVCContrib/EnumerableExtensions.cs
/// <summary>
/// Converts the source sequence into an IEnumerable of SelectListItem
/// </summary>
/// <param name="items">Source sequence</param>
/// <param name="nameSelector">Lambda that specifies the name for the SelectList items</param>
/// <param name="valueSelector">Lambda that specifies the value for the SelectList items</param>
/// <param name="selectedValueSelector">Lambda that specifies whether the item should be selected</param>
/// <returns>IEnumerable of SelectListItem</returns>
Converts the source sequence into an IEnumerable of SelectListItem
Converts the source sequence into an IEnumerable of SelectListItem
public static IEnumerable<SelectListItem> ToSelectList<TItem, TValue>(this IEnumerable<TItem> items, Func<TItem, TValue> valueSelector, Func<TItem, string> nameSelector, Func<TItem, bool> selectedValueSelector) 
		{
			foreach (var item in items) 
			{
				var value = valueSelector(item);
				yield return new SelectListItem
				{
					Text = nameSelector(item),
					Value = value.ToString(),
					Selected = selectedValueSelector(item)
				};
			}
		}
public static IEnumerable < SelectListItem > ToSelectList < TItem , TValue > ( this IEnumerable < TItem > items , Func < TItem , TValue > valueSelector , Func < TItem , string > nameSelector , Func < TItem , bool > selectedValueSelector ) { foreach ( var item in items ) { var value = valueSelector ( item ) ; yield return new SelectListItem { Text = nameSelector ( item ) , Value = value . ToString ( ) , Selected = selectedValueSelector ( item ) } ; } }
Converts the source sequence into an IEnumerable of SelectListItem
Converts the source sequence into an IEnumerable of SelectListItem
IEnumerable of SelectListItem
IEnumerable of SelectListItem
IEnumerable<TItem>
this
valueSelector
Func<TItem, TValue>
Lambda that specifies the value for the SelectList items
Lambda that specifies the value for the SelectList items
nameSelector
Func<TItem, string>
Lambda that specifies the name for the SelectList items
Lambda that specifies the name for the SelectList items
selectedValueSelector
Func<TItem, bool>
Lambda that specifies whether the item should be selected
Lambda that specifies whether the item should be selected
items
None