DropDownHelper.GetDropdown(T) Method (IEnumerable(T), Func(T, String), Func(T, String), Int32)

Template MVC

DropDownHelperGetDropdownT Method (IEnumerableT, FuncT, String, FuncT, String, Int32)

Generate a list of SelectListItem

Namespace:  Template.Web.Commons.Utils
Assembly:  Template.Web (in Template.Web.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public static IEnumerable<SelectListItem> GetDropdown<T>(
	IEnumerable<T> listModel,
	Func<T, string> key,
	Func<T, string> text,
	int selected = 0
)

Parameters

listModel
Type: System.Collections.GenericIEnumerableT
The list source of the model
key
Type: SystemFuncT, String
A function to get the property of the model to use as a key of the dropdown
text
Type: SystemFuncT, String
A function to get the property of the model to use as a value text of the dropdown
selected (Optional)
Type: SystemInt32
Index of which element whatns to be selected of the begining, default 0

Type Parameters

T
The Model type for generate the list

Return Value

Type: IEnumerableSelectListItem
A list of SelectedListItem ready to use as a source of a dropdown with Razor
See Also