HtmlHelper.DropDownList Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a single-selection HTML <select> element for the expression
. Adds
<option> elements based on optionLabel
and selectList
. Adds a
"selected" attribute to an <option> if its Value (if non-null
) or
Text matches the first non-null
value found in:
the ModelState entry with full name,
the ViewData entry with full name (unless used instead of selectList
), or
the expression
evaluated against Model.
See Name(String) for more information about a "full name".
public:
virtual Microsoft::AspNetCore::Html::IHtmlContent ^ DropDownList(System::String ^ expression, System::Collections::Generic::IEnumerable<Microsoft::AspNetCore::Mvc::Rendering::SelectListItem ^> ^ selectList, System::String ^ optionLabel, System::Object ^ htmlAttributes);
public Microsoft.AspNetCore.Html.IHtmlContent DropDownList (string expression, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> selectList, string optionLabel, object htmlAttributes);
abstract member DropDownList : string * seq<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> * string * obj -> Microsoft.AspNetCore.Html.IHtmlContent
override this.DropDownList : string * seq<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> * string * obj -> Microsoft.AspNetCore.Html.IHtmlContent
Public Function DropDownList (expression As String, selectList As IEnumerable(Of SelectListItem), optionLabel As String, htmlAttributes As Object) As IHtmlContent
Parameters
- expression
- String
Expression name, relative to the current model.
- selectList
- IEnumerable<SelectListItem>
A collection of SelectListItem objects used to populate the <select> element with
<optgroup> and <option> elements. If null
, uses the ViewData entry with
full name and that entry must be a collection of SelectListItem objects.
- optionLabel
- String
The text for a default empty item. Does not include such an item if argument is null
.
- htmlAttributes
- Object
An Object that contains the HTML attributes for the <select> element. Alternatively, an IDictionary<TKey,TValue> instance containing the HTML attributes.
Returns
A new IHtmlContent containing the <select> element.