Dela via


IHtmlHelper<TModel>.ListBoxFor<TResult> Method

Definition

Returns a multi-selection <select> element for the expression. Adds <option> elements based on selectList. Adds a "selected" attribute to an <option> if its Value (if non-null) or Text matches an entry in the first non-null collection found in: the ModelState entry with full name, or the expression evaluated against Model. See NameFor<TResult>(Expression<Func<TModel,TResult>>) for more information about a "full name".

public:
generic <typename TResult>
 Microsoft::AspNetCore::Html::IHtmlContent ^ ListBoxFor(System::Linq::Expressions::Expression<Func<TModel, TResult> ^> ^ expression, System::Collections::Generic::IEnumerable<Microsoft::AspNetCore::Mvc::Rendering::SelectListItem ^> ^ selectList, System::Object ^ htmlAttributes);
public Microsoft.AspNetCore.Html.IHtmlContent ListBoxFor<TResult> (System.Linq.Expressions.Expression<Func<TModel,TResult>> expression, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> selectList, object htmlAttributes);
abstract member ListBoxFor : System.Linq.Expressions.Expression<Func<'Model, 'Result>> * seq<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> * obj -> Microsoft.AspNetCore.Html.IHtmlContent
Public Function ListBoxFor(Of TResult) (expression As Expression(Of Func(Of TModel, TResult)), selectList As IEnumerable(Of SelectListItem), htmlAttributes As Object) As IHtmlContent

Type Parameters

TResult

The type of the expression result.

Parameters

expression
Expression<Func<TModel,TResult>>

An expression to be evaluated against the current model.

selectList
IEnumerable<SelectListItem>

A collection of SelectListItem objects used to populate the <select> element with <optgroup> and <option> elements. If null, finds the SelectListItem collection with name expression in ViewData.

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.

Remarks

Combines HtmlFieldPrefix and the string representation of the expression to set <select> element's "name" attribute. Sanitizes the string representation of the expression to set element's "id" attribute.

Applies to