HtmlHelperSelectExtensions.ListBox 方法

定義

多載

ListBox(IHtmlHelper, String)

傳回 的 expression 多重選取專案。 >< 根據具有完整名稱的專案加入 <ViewData 選項 > 專案。 如果 (非) 或 Text 符合中找到的第一個非 null 值,請將 「selected」 屬性 < 加入至選項 > : ModelState 具有完整名稱的專案,或 expression 針對 評估的 ModelnullValue 如需有關「完整名稱」的詳細資訊,請參閱 Name(String)

ListBox(IHtmlHelper, String, IEnumerable<SelectListItem>)

傳回 的 expression 多重選取專案。 >< 根據 selectList 加入 < 選項 > 專案。 如果 (非 Value) 或 Text 符合中找到的第一個非 null 值,則將其 「selected」 屬性 < 加入至選項 > : ModelState 具有完整名稱的專案、 ViewData 具有完整名稱的專案 (,除非使用 而非 selectList) ,或 expression 針對 評估的 Modelnull 如需有關「完整名稱」的詳細資訊,請參閱 Name(String)

ListBox(IHtmlHelper, String)

來源:
HtmlHelperSelectExtensions.cs
來源:
HtmlHelperSelectExtensions.cs
來源:
HtmlHelperSelectExtensions.cs

傳回 的 expression 多重選取專案。 >< 根據具有完整名稱的專案加入 <ViewData 選項 > 專案。 如果 (非) 或 Text 符合中找到的第一個非 null 值,請將 「selected」 屬性 < 加入至選項 > : ModelState 具有完整名稱的專案,或 expression 針對 評估的 ModelnullValue 如需有關「完整名稱」的詳細資訊,請參閱 Name(String)

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::AspNetCore::Html::IHtmlContent ^ ListBox(Microsoft::AspNetCore::Mvc::Rendering::IHtmlHelper ^ htmlHelper, System::String ^ expression);
public static Microsoft.AspNetCore.Html.IHtmlContent ListBox (this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper htmlHelper, string expression);
static member ListBox : Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper * string -> Microsoft.AspNetCore.Html.IHtmlContent
<Extension()>
Public Function ListBox (htmlHelper As IHtmlHelper, expression As String) As IHtmlContent

參數

htmlHelper
IHtmlHelper

IHtmlHelper這個方法擴充的實例。

expression
String

相對於目前模型的運算式名稱。

傳回

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

備註

結合 HtmlFieldPrefixexpression 以設定 < select > 元素的 「name」 屬性。 expression清理以設定專案的 「id」 屬性。

ViewData具有完整名稱的專案必須是非 null 物件的集合 SelectListItem

適用於

ListBox(IHtmlHelper, String, IEnumerable<SelectListItem>)

來源:
HtmlHelperSelectExtensions.cs
來源:
HtmlHelperSelectExtensions.cs
來源:
HtmlHelperSelectExtensions.cs

傳回 的 expression 多重選取專案。 >< 根據 selectList 加入 < 選項 > 專案。 如果 (非 Value) 或 Text 符合中找到的第一個非 null 值,則將其 「selected」 屬性 < 加入至選項 > : ModelState 具有完整名稱的專案、 ViewData 具有完整名稱的專案 (,除非使用 而非 selectList) ,或 expression 針對 評估的 Modelnull 如需有關「完整名稱」的詳細資訊,請參閱 Name(String)

public:
[System::Runtime::CompilerServices::Extension]
 static Microsoft::AspNetCore::Html::IHtmlContent ^ ListBox(Microsoft::AspNetCore::Mvc::Rendering::IHtmlHelper ^ htmlHelper, System::String ^ expression, System::Collections::Generic::IEnumerable<Microsoft::AspNetCore::Mvc::Rendering::SelectListItem ^> ^ selectList);
public static Microsoft.AspNetCore.Html.IHtmlContent ListBox (this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper htmlHelper, string expression, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> selectList);
static member ListBox : Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper * string * seq<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> -> Microsoft.AspNetCore.Html.IHtmlContent
<Extension()>
Public Function ListBox (htmlHelper As IHtmlHelper, expression As String, selectList As IEnumerable(Of SelectListItem)) As IHtmlContent

參數

htmlHelper
IHtmlHelper

IHtmlHelper這個方法擴充的實例。

expression
String

相對於目前模型的運算式名稱。

selectList
IEnumerable<SelectListItem>

物件的集合 SelectListItem ,用來以 < optgroup > 和 < option > 元素填 < 入 select > 元素。 如果 nullViewData ,則使用具有完整名稱的專案,而且該專案必須是 物件的集合 SelectListItem

傳回

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

備註

結合 HtmlFieldPrefixexpression 以設定 < select > 元素的 「name」 屬性。 expression清理以設定專案的 「id」 屬性。

適用於