Skip to content

Instantly share code, notes, and snippets.

@JerryNixon
Created November 6, 2020 22:28
Show Gist options
  • Select an option

  • Save JerryNixon/7ef3bf3a0a4f8de2f7563216960edc2e to your computer and use it in GitHub Desktop.

Select an option

Save JerryNixon/7ef3bf3a0a4f8de2f7563216960edc2e to your computer and use it in GitHub Desktop.
Blazor troubles with cascading InputSelect
@page "/"
<EditForm Model="@Model">
First
<InputSelect @bind-Value="Model.First" class="form-control" @oninput="FirstChanged">
@foreach (var item in FirstList)
{
<option value="@item">@item</option>
}
</InputSelect>
Second
<InputSelect @bind-Value="Model.Second" class="form-control">
@foreach (var item in SecondList)
{
<option value="@item">@item</option>
}
</InputSelect>
</EditForm>
@code
{
public class Record
{
public string First { get; set; }
public string Second { get; set; }
}
public Record Model { get; set; } = new Record();
public List<string> FirstList { get; set; } = new List<string> { "A", "B", "C", "D" };
public List<string> SecondList { get; set; } = new List<string>();
public void FirstChanged()
{
SecondList = Enumerable.Range(1, 5).Select(x => $"{Model.First}-{x}").ToList();
StateHasChanged();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment