HtmlHelperSelectExtensions.ListBoxFor(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>) HtmlHelperSelectExtensions.ListBoxFor(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>) HtmlHelperSelectExtensions.ListBoxFor(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>) 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 the first non-null value found in: the ModelState entry with full name, or the expression evaluated against Model. See Name(String) for more information about a "full name".

public static Microsoft.AspNetCore.Html.IHtmlContent ListBoxFor<TModel,TResult> (this Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> htmlHelper, System.Linq.Expressions.Expression<Func<TModel,TResult>> expression, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> selectList);
static member ListBoxFor : Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<'Model> * System.Linq.Expressions.Expression<Func<'Model, 'Result>> * seq<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> -> Microsoft.AspNetCore.Html.IHtmlContent
<Extension()>
Public Function ListBoxFor(Of TModel, TResult) (htmlHelper As IHtmlHelper(Of TModel), expression As Expression(Of Func(Of TModel, TResult)), selectList As IEnumerable(Of SelectListItem)) As IHtmlContent

Type Parameters

TModel

The type of the model.

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, uses the ViewData entry with full name and that entry must be a collection of SelectListItem objects.

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