SelectList IEnumerable<SelectListItem>

.SelectList()

Takes a list of SelectListItem and converts them into a SelectList.

Method

public static SelectList SelectList(this IEnumerable<SelectListItem> source, bool firstEmpty = true, string emptyValue = "", bool emptyGuid = false)
IEnumerable<SelectListItem> source

A list of SelectListItem to convert into a 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.ManualList = (new SelectListItem[]
{
new SelectListItem() { Text = "One", Value = "1" },
new SelectListItem() { Text = "Two", Value = "2" }
}).SelectList();