N

Cascading selects

Select A's value determines select B's options. Changing A re-renders B from the server.

#When to use

Country → state, region → zone, project → environment, team → member. Any dependent dropdown where B's options are too many to ship up front.

#Markup

html
<select name="country"
        hx-get="/regions/states"
        hx-trigger="change"
        hx-target="#state_select"
        hx-swap="outerHTML">
    <option value="US">United States</option>
    <option value="CA">Canada</option>
    <option value="MX">Mexico</option>
</select>

<select id="state_select" name="state">
    <partial name="_StateOptions" model="Model.States" />
</select>

hx-include="this" is implicit — the changed cleanly.

#Preserve the current value

If you're editing an existing record, pass the selected state via ViewData and emit selected on the matching :

cshtml
<option value="@r.Code" selected="@(r.Code == ViewData["State"] ? "selected" : null)">@r.Name</option>