HtmlHelperSelectExtensions.DropDownListFor Method

Definition

Overloads

DropDownListFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>)

Returns a single-selection HTML <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 NameFor<TResult>(Expression<Func<TModel,TResult>>) for more information about a "full name".

DropDownListFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>, Object)

Returns a single-selection HTML <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 NameFor<TResult>(Expression<Func<TModel,TResult>>) for more information about a "full name".

DropDownListFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>, String)

Returns a single-selection HTML <select> element for the expression. Adds <option> elements based on optionLabel and 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 NameFor<TResult>(Expression<Func<TModel,TResult>>) for more information about a "full name".

DropDownListFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>)

Source:
HtmlHelperSelectExtensions.cs
Source:
HtmlHelperSelectExtensions.cs
Source:
HtmlHelperSelectExtensions.cs

Returns a single-selection HTML <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 NameFor<TResult>(Expression<Func<TModel,TResult>>) for more information about a "full name".

C#
public static Microsoft.AspNetCore.Html.IHtmlContent DropDownListFor<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);

Type Parameters

TModel

The type of the model.

TResult

The type of the expression result.

Parameters

htmlHelper
IHtmlHelper<TModel>

The IHtmlHelper<TModel> instance this method extends.

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

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

DropDownListFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>, Object)

Source:
HtmlHelperSelectExtensions.cs
Source:
HtmlHelperSelectExtensions.cs
Source:
HtmlHelperSelectExtensions.cs

Returns a single-selection HTML <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 NameFor<TResult>(Expression<Func<TModel,TResult>>) for more information about a "full name".

C#
public static Microsoft.AspNetCore.Html.IHtmlContent DropDownListFor<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, object htmlAttributes);

Type Parameters

TModel

The type of the model.

TResult

The type of the expression result.

Parameters

htmlHelper
IHtmlHelper<TModel>

The IHtmlHelper<TModel> instance this method extends.

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.

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

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0

DropDownListFor<TModel,TResult>(IHtmlHelper<TModel>, Expression<Func<TModel,TResult>>, IEnumerable<SelectListItem>, String)

Source:
HtmlHelperSelectExtensions.cs
Source:
HtmlHelperSelectExtensions.cs
Source:
HtmlHelperSelectExtensions.cs

Returns a single-selection HTML <select> element for the expression. Adds <option> elements based on optionLabel and 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 NameFor<TResult>(Expression<Func<TModel,TResult>>) for more information about a "full name".

C#
public static Microsoft.AspNetCore.Html.IHtmlContent DropDownListFor<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, string optionLabel);

Type Parameters

TModel

The type of the model.

TResult

The type of the expression result.

Parameters

htmlHelper
IHtmlHelper<TModel>

The IHtmlHelper<TModel> instance this method extends.

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.

optionLabel
String

The text for a default empty item. Does not include such an item if argument is null.

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

ASP.NET Core 9.0 and other versions
Product Versions
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0