Share via


HtmlHelper.DropDownList 方法

定义

返回 的单expression选 HTML <select> 元素。 添加<基于 optionLabelselectList的选项>元素。 如果选项 (非) 或Text与中找到的第一个<非null值匹配,则向Value选项>添加“selected”属性:ModelState具有全名的条目、ViewData (全名项(除非使用而不是 selectList) )或expression针对 Model求值的 。null 有关“全名”的详细信息,请参阅 Name(String)

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

参数

expression
String

表达式名称,相对于当前模型。

selectList
IEnumerable<SelectListItem>

对象的集合SelectListItem,用于使用 <optgroup> 和 <option> 元素填充 <select> 元素。 如果 null为 ,则 ViewData 使用具有全名的条目,并且该条目必须是 对象的集合 SelectListItem

optionLabel
String

默认空项的文本。 如果参数为 null,则不包括此类项。

htmlAttributes
Object

一个 Object ,它包含 select> 元素的 <HTML 属性。 或者,一个 IDictionary<TKey,TValue> 包含 HTML 属性的实例。

返回

包含 <select> 元素的新IHtmlContent

实现

适用于