共用方式為


HtmlHelper.DropDownList 方法

定義

傳回 的單一選取 HTML < 選取 > 專案 expression 。 根據 optionLabelselectList 加入 < 選項 > 專案。 如果 Value (非 null) 或 Text 符合中找到的第一個非 null 值,則會將 「selected」 屬性 < 加入至選項 > : ModelState 具有完整名稱的專案、 ViewData 具有完整名稱的專案 (,除非使用 selectList 而非) ,否則 expression 會針對 Model 進行評估。 如需有關「完整名稱」的詳細資訊,請參閱 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 屬性的實例。

傳回

新的 IHtmlContent ,其中包含 < select > 元素。

實作

適用於