Skip to content

StaticSelect

Abstract Inherits: StaticInputBase

StaticSelect is the headless base class for <select> components. It adds an Items property mapped from the consumer-facing asp-items attribute, so consumers can supply options exactly as they would to a native <select>.

Inside the component’s Razor template, bind the inner <select> via the static-for and static-items tag helpers.

TechGems.StaticComponents.Headless
using TechGems.StaticComponents.Headless;
namespace YourAssembly.Views.Components;
public class PinesSelect : StaticSelect { }
@* ~/Views/Components/PinesSelect.cshtml *@
@model PinesSelect
<select static-for="@Model.InputExpression"
static-items="@Model.Items"
disabled="@(Model.Disabled ? "disabled" : null)"
class="">
</select>
@* consumer view *@
<pines-select asp-for="Form.Department"
asp-items="@Model.DepartmentOptions"></pines-select>
[HtmlAttributeName("asp-items")]
public List<SelectListItem> Items { get; set; } = new List<SelectListItem>();

The list of SelectListItems rendered as <option> tags inside the inner <select>. Items that share a SelectListGroup reference are grouped into a single <optgroup> at the position of the group’s first occurrence.

AttributeValue
HTML attributeasp-items
RequiredNo
Defaultempty list
  • InputExpression (asp-for)
  • ShowLabel (show-label)
  • Disabled (disabled)

See StaticInputBase for the full descriptions.

ProcessAsync(TagHelperContext context, TagHelperOutput output)

Section titled “ProcessAsync(TagHelperContext context, TagHelperOutput output)”
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)

Delegates to StaticInputBase.ProcessAsync.