I have these two snippets of Razor code, one piece is in the .razor file, the other is in the .razor.cs file.
There are two InputSelect controls and depending on which one of three is selected in the first control will then decide which options are shown in the second InputSelect control.
The logic is as follows:
If value = 1 is selected, only value = 7 will be shown in the second
InputSelectcontrolIf value = 2 is selected, only values 5 and 6 will be shown in the second
InputSelectcontrolIf value = 3 is selected, values 1-4 will be shown in the second
InputSelectcontrol
I have tested the code and it runs without any error, but on selection of the value in the first InputSection, the breakpoint does not trigger the OnChange statement in the .razor.cs file.
Due to this, no options are displayed in the second InputSelect control.
This is the code in the .razor file:
<div class="form-group"><label class="col-form-label" for="Select1">Select1</label><InputSelect @bind-Value="DatabaseDto.Select1ID" class="form-select" @onchange="OnSelect1Changed" id="Select1"><option value="0">Please Select a Select1 Option</option> @foreach (var Select1 in _Select1List) {<option value="@Select1?.Select1ID">@Select1?.Select1Name</option> }</InputSelect><ValidationMessage class="text-danger" For="@(() => ClozapineDto.Select1ID)" /></div><div class="form-group"><div class="form-group"><label class="col-form-label" for="Select2">Select2</label><InputSelect class="form-select" @bind-Value="DatabaseDto.Select2ID"><option value="0">Please Select a Select2</option> @foreach (var Select2 in FilteredSelect2) {<option value="@Select2?.Select2ID">@Select2?.Select2Name</option> }</InputSelect></div></div>The code in .razor.cs file is:
private async Task OnBloodChanged( ChangeEventArgs e ) { if ( int.TryParse( e.Value?.ToString(), out int _selectedBloodID ) ) { ClozapineDto.BloodID = _selectedBloodID; FilteredWeeks = _selectedBloodID switch { 1 => _WeekList?.Where(w => w?.WeekID == 5) ?? [], 2 => _WeekList?.Where(w => w?.WeekID is 6 or 7) ?? [], 3 => _WeekList?.Where(w => _week_options_for_blood_id_3.Contains(w?.WeekID ?? 0)) ?? [], _ => [] }; ClozapineDto.WeekID = 0; // reset Week selection if BloodID changes StateHasChanged(); }}