IHtmlGenerator.GenerateSelect Method

Definition

Overloads

GenerateSelect(ViewContext, ModelExplorer, String, String, IEnumerable<SelectListItem>, Boolean, Object)

Source:
IHtmlGenerator.cs

Generate a <select> element for the expression.

C#
public Microsoft.AspNetCore.Mvc.Rendering.TagBuilder GenerateSelect (Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer modelExplorer, string optionLabel, string expression, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> selectList, bool allowMultiple, object htmlAttributes);

Parameters

viewContext
ViewContext

A ViewContext instance for the current scope.

modelExplorer
ModelExplorer

ModelExplorer for the expression. If null, determines validation attributes using viewContext and the expression.

optionLabel
String

Optional text for a default empty <option> element.

expression
String

Expression name, relative to 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 this collection at ViewContext.ViewData[expression].

allowMultiple
Boolean

If true, includes a multiple attribute in the generated HTML. Otherwise generates a single-selection <select> element.

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 TagBuilder describing the <select> element.

Remarks

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

See GetCurrentValues(ViewContext, ModelExplorer, String, Boolean) for information about how current values are determined.

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

GenerateSelect(ViewContext, ModelExplorer, String, String, IEnumerable<SelectListItem>, ICollection<String>, Boolean, Object)

Source:
IHtmlGenerator.cs

Generate a <select> element for the expression.

C#
public Microsoft.AspNetCore.Mvc.Rendering.TagBuilder GenerateSelect (Microsoft.AspNetCore.Mvc.Rendering.ViewContext viewContext, Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer modelExplorer, string optionLabel, string expression, System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Mvc.Rendering.SelectListItem> selectList, System.Collections.Generic.ICollection<string> currentValues, bool allowMultiple, object htmlAttributes);

Parameters

viewContext
ViewContext

A ViewContext instance for the current scope.

modelExplorer
ModelExplorer

ModelExplorer for the expression. If null, determines validation attributes using viewContext and the expression.

optionLabel
String

Optional text for a default empty <option> element.

expression
String

Expression name, relative to 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 this collection at ViewContext.ViewData[expression].

currentValues
ICollection<String>

An ICollection<T> containing values for <option> elements to select. If null, selects <option> elements based on Selected values in selectList.

allowMultiple
Boolean

If true, includes a multiple attribute in the generated HTML. Otherwise generates a single-selection <select> element.

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 TagBuilder describing the <select> element.

Remarks

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

See GetCurrentValues(ViewContext, ModelExplorer, String, Boolean) for information about how the currentValues collection may be created.

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