SelectExtensions Class
Represents support for making selections in a list.
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
| Name | Description | |
|---|---|---|
![]() ![]() | DropDownList(HtmlHelper, String) | Returns a single-selection select element using the specified HTML helper and the name of the form field. |
![]() ![]() | DropDownList(HtmlHelper, String, IEnumerable(SelectListItem)) | Returns a single-selection select element using the specified HTML helper, the name of the form field, and the specified list items. |
![]() ![]() | DropDownList(HtmlHelper, String, String) | Returns a single-selection select element using the specified HTML helper, the name of the form field, and an option label. |
![]() ![]() | DropDownList(HtmlHelper, String, IEnumerable(SelectListItem), IDictionary(String, Object)) | Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, and the specified HTML attributes. |
![]() ![]() | DropDownList(HtmlHelper, String, IEnumerable(SelectListItem), Object) | Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, and the specified HTML attributes. |
![]() ![]() | DropDownList(HtmlHelper, String, IEnumerable(SelectListItem), String) | Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, and an option label. |
![]() ![]() | DropDownList(HtmlHelper, String, IEnumerable(SelectListItem), String, IDictionary(String, Object)) | Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, an option label, and the specified HTML attributes. |
![]() ![]() | DropDownList(HtmlHelper, String, IEnumerable(SelectListItem), String, Object) | Returns a single-selection select element using the specified HTML helper, the name of the form field, the specified list items, an option label, and the specified HTML attributes. |
![]() ![]() | DropDownListFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem)) | Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items. |
![]() ![]() | DropDownListFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem), IDictionary(String, Object)) | Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items and HTML attributes. |
![]() ![]() | DropDownListFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem), Object) | Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items and HTML attributes. |
![]() ![]() | DropDownListFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem), String) | Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items and option label. |
![]() ![]() | DropDownListFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem), String, IDictionary(String, Object)) | Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items, option label, and HTML attributes. |
![]() ![]() | DropDownListFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem), String, Object) | Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items, option label, and HTML attributes. |
![]() ![]() | ListBox(HtmlHelper, String) | Returns a multi-select select element using the specified HTML helper and the name of the form field. |
![]() ![]() | ListBox(HtmlHelper, String, IEnumerable(SelectListItem)) | Returns a multi-select select element using the specified HTML helper, the name of the form field, and the specified list items. |
![]() ![]() | ListBox(HtmlHelper, String, IEnumerable(SelectListItem), IDictionary(String, Object)) | Returns a multi-select select element using the specified HTML helper, the name of the form field, the specified list items, and the specified HMTL attributes. |
![]() ![]() | ListBox(HtmlHelper, String, IEnumerable(SelectListItem), Object) | Returns a multi-select select element using the specified HTML helper, the name of the form field, and the specified list items. |
![]() ![]() | ListBoxFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem)) | Returns an HTML select element for each property in the object that is represented by the specified expression and using the specified list items. |
![]() ![]() | ListBoxFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem), IDictionary(String, Object)) | Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items and HTML attributes. |
![]() ![]() | ListBoxFor(TModel, TProperty)(HtmlHelper(TModel), Expression(Func(TModel, TProperty)), IEnumerable(SelectListItem), Object) | Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items and HTML attributes. |
The SelectExtensions class contains methods that extend the HtmlHelper class. Each extension method renders an HTML select element. The DropDownList method renders an element that enables the user to select an item from a drop-down list. The ListBox method renders an element that enables the user to select from a scrolling list of items.
The following example shows how to use both the DropDownList and ListBox methods in a view. The ListBox control displays a list of book titles, from which the user can select one or more books. The DropDownList displays a list of pets, from which the user can select one pet. The selections are then displayed in another view.
The following classes define the data model that is used for a book and a pet.
Public Class Book Private _Id As Integer Public Property Id() As Integer Get Return _Id End Get Set(ByVal value As Integer) _Id = value End Set End Property Private _Title As String Public Property Title() As String Get Return _Title End Get Set(ByVal value As String) _Title = value End Set End Property End Class Public Class Pet Private _Id As Integer Public Property Id() As Integer Get Return _Id End Get Set(ByVal value As Integer) _Id = value End Set End Property Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value End Set End Property End Class
In the following example, the list of items for each control is created in the Index action method and passed to the view in the ViewDataDictionary object.
The following example shows a view that displays the entry form that contains the list box and the drop-down list. The list box is passed an anonymous object that defines the HMTL size attribute for the rendered list box.
When the user submits the form, the Selection action method handles the request and renders the view that displays the selections.
The following view displays the user selections.
