Export (0) Print
Expand All

SelectExtensions Class

Represents support for making selections in a list.

System.Object
  System.Web.Mvc.Html.SelectExtensions

Namespace:  System.Web.Mvc.Html
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

'Declaration
<ExtensionAttribute> _
Public NotInheritable Class SelectExtensions
'Usage

  NameDescription
Public methodStatic memberDropDownList(HtmlHelper, String)Returns a single-selection select element using the specified HTML helper and the name of the form field.
Public methodStatic memberDropDownList(HtmlHelper, String, IEnumerable(Of SelectListItem))Returns a single-selection select element using the specified HTML helper, the name of the form field, and the specified list items.
Public methodStatic memberDropDownList(HtmlHelper, String, String)Returns a single-selection select element using the specified HTML helper, the name of the form field, and an option label.
Public methodStatic memberDropDownList(HtmlHelper, String, IEnumerable(Of SelectListItem), IDictionary(Of 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.
Public methodStatic memberDropDownList(HtmlHelper, String, IEnumerable(Of 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.
Public methodStatic memberDropDownList(HtmlHelper, String, IEnumerable(Of 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.
Public methodStatic memberDropDownList(HtmlHelper, String, IEnumerable(Of SelectListItem), String, IDictionary(Of 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.
Public methodStatic memberDropDownList(HtmlHelper, String, IEnumerable(Of 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.
Public methodStatic memberDropDownListFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of SelectListItem))Returns an HTML select element for each property in the object that is represented by the specified expression using the specified list items.
Public methodStatic memberDropDownListFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of SelectListItem), IDictionary(Of 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.
Public methodStatic memberDropDownListFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of 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.
Public methodStatic memberDropDownListFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of 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.
Public methodStatic memberDropDownListFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of SelectListItem), String, IDictionary(Of 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.
Public methodStatic memberDropDownListFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of 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.
Public methodStatic memberListBox(HtmlHelper, String)Returns a multi-select select element using the specified HTML helper and the name of the form field.
Public methodStatic memberListBox(HtmlHelper, String, IEnumerable(Of SelectListItem))Returns a multi-select select element using the specified HTML helper, the name of the form field, and the specified list items.
Public methodStatic memberListBox(HtmlHelper, String, IEnumerable(Of SelectListItem), IDictionary(Of 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.
Public methodStatic memberListBox(HtmlHelper, String, IEnumerable(Of SelectListItem), Object)Returns a multi-select select element using the specified HTML helper, the name of the form field, and the specified list items.
Public methodStatic memberListBoxFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of 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.
Public methodStatic memberListBoxFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of SelectListItem), IDictionary(Of 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.
Public methodStatic memberListBoxFor(Of TModel, TProperty)(HtmlHelper(Of TModel), Expression(Of Func(Of TModel, TProperty)), IEnumerable(Of 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.
Top

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.

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft