I am new to Blazor and I'm trying to do an Add and Edit form , I have a FormComponent which is used on an Add and Edit razor page, all good. On this page I have cascading dropdowns, and these work well on the Add page, but on the edit page when I repopulate the data, the first dropdown has the correct data and the correct data is selected but the subsequent dropdown isn't present. My thoughts are that the ValueChanged event isn't being fired, please see the code below
@if (Level1Categories is not null)
{
<div class="nhsuk-grid-row mb-2">
<div class="nhsuk-grid-column-one-third">
<label class="nhsuk-label">Category:</label>
</div>
<div class="nhsuk-grid-column-two-thirds">
<InputSelect id="category" class="nhsuk-select"
ValueChanged="@((int s) => GetCategoriesById(s))" Value="Links.LevelId"
ValueExpression="@(() => Links.LevelId)">
@if (Level1Categories is not null)
{
<option value="0">Please Select</option>
@foreach (var category in Level1Categories)
{
<option value="@category.Id">@category.Description</option>
}
</InputSelect>
</div>
</div>
}
@if (Categories is not null && Categories.Count > 0)
{
<div class="nhsuk-grid-row mb-2">
<div class="nhsuk-grid-column-one-third">
<label class="nhsuk-label">Sub Category:</label>
</div>
<div class="nhsuk-grid-column-two-thirds">
<InputSelect id="category" class="nhsuk-select" ValueChanged="@((int s) =>
GetSpecialtiesById(s))" Value="Links.CategoryId"
ValueExpression="@(() => Links.CategoryId)">
@if (Categories is not null)
{
<option value="0">Please Select</option>
@foreach (var category in Categories)
{
<option value="@category.Id">@category.Description</option>
}
}
</InputSelect>
</div>
</div>
}
Below is the c# code for both of the ValueChanged events. This all works well and as expected for the add but not the edit
private async Task GetCategoriesById(int val)
{
Links.LevelId = val;
var query = new GetCategoriesByIdQuery()
{
CategoryId = val
};
Categories = (List<CategoryModel>) await _mediator.Send(query);
}
private async Task GetSpecialtiesById(int val)
{
Links.CategoryId = val;
var query = new GetCategoriesByIdQuery()
{
CategoryId = val
};
Specialties = (List<CategoryModel>) await _mediator.Send(query);
}
On the Edit page itself
<LinkForm Links="@Links" IsBusy="@IsBusy" IsEdit="true"
Level1Categories="Level1Categories" OnCancel="NavigateToOverviewPage"
OnSubmit="@HandleSubmit">
</LinkForm>
protected override async Task OnParametersSetAsync()
{
IsBusy = true;
try
{
var command = new GetLinkQuery()
{
LinkId = LinkId
};
Links = await _mediator.Send(command);
}
finally
{
IsBusy = false;
}
}
So basically I want to know how I can get the ValueChanged event to fire when the edit data is populated, I would expect it to fire because the value is changing, but it isn't. Any help would be very much appreciated. Thanks
