HtmlHelper.ListBox Method (String, String, IEnumerable<SelectListItem>, IDictionary<String, Object>)

Returns an HTML list box control that has the specified name and custom attributes defined by an attribute dictionary, and that contains the specified list items and default item.

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


Public Function ListBox ( _
    name As String, _
    defaultOption As String, _
    selectList As IEnumerable(Of SelectListItem), _
    htmlAttributes As IDictionary(Of String, Object) _
) As IHtmlString
Dim instance As HtmlHelper 
Dim name As String 
Dim defaultOption As String 
Dim selectList As IEnumerable(Of SelectListItem)
Dim htmlAttributes As IDictionary(Of String, Object)
Dim returnValue As IHtmlString 

returnValue = instance.ListBox(name, defaultOption, _
    selectList, htmlAttributes)
public IHtmlString ListBox(
    string name,
    string defaultOption,
    IEnumerable<SelectListItem> selectList,
    IDictionary<string, Object> htmlAttributes
IHtmlString^ ListBox(
    String^ name, 
    String^ defaultOption, 
    IEnumerable<SelectListItem^>^ selectList, 
    IDictionary<String^, Object^>^ htmlAttributes
member ListBox : 
        name:string * 
        defaultOption:string * 
        selectList:IEnumerable<SelectListItem> * 
        htmlAttributes:IDictionary<string, Object> -> IHtmlString
public function ListBox(
    name : String, 
    defaultOption : String, 
    selectList : IEnumerable<SelectListItem>, 
    htmlAttributes : IDictionary<String, Object>
) : IHtmlString


  • name
    Type: System.String
    The value to assign to the name attribute of the HTML select element.
  • defaultOption
    Type: System.String
    The text to display for the default option in the list.

Return Value

Type: System.Web.IHtmlString
The HTML markup that represents the list box control.


Exception Condition

name is null reference (Nothing in Visual Basic) or empty.


The returned markup consists of an HTML select element in the following form:

<select name="name" multiple="multiple" ...htmlAttributes...>
  <option value="selectList[0].Value">selectList[0].Text</option>
  <option value="selectList[1].Value">selectList[1].Text</option>

See Also


HtmlHelper Class

ListBox Overload

System.Web.WebPages.Html Namespace