I have the two pieces of Razor code, one piece is in the .Razor file the other is in the .razor.cs file.There are two InputSelect commands and depending on which one of three is selected in the first command will then decide which options are shown in the second InputSelect Command.
The logic is as follows:
Value 1 is selected will show only value 7 in the second InputSelectStatement.
Value 2 is selected will show values 5 and 6 in the secondInputSelect Statement.
Value 3 is selected will show values 1-4 in the second InputSelectStatement.
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 in the onchange statement in the razor.cs file.Due to this, no options are displayed in the Second InputSelect command.
The code in the .razor file is:
<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();