Created
November 6, 2020 22:28
-
-
Save JerryNixon/7ef3bf3a0a4f8de2f7563216960edc2e to your computer and use it in GitHub Desktop.
Blazor troubles with cascading InputSelect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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