I am working on a Blazor server app.
I am trying to pass a parameter (int platformId) from parent component to child component. The platformId defines the platform, and changing it should result in a different set of data rendered in child component.
A button is used to toggle between 2 different platformIds.
I pass the platformId successfully to child component as it's changed, but so far I couldn’t find the way to populate listOfGrades with data from changed platform.
It seems that once the PlatformId is set as here <ChildComponent @ref="childComponent1" PlatformId="platformId" /> it just cannot be changed.
Parent component:
@code{
int platformId = 1;
bool defaultSelected = false;
public void ToggleId()
{
defaultSelected = !defaultSelected;
SetPlatformId();
}
public void SetPlatformId()
{
if (defaultSelected)
platformId = 1;
else
platformId = 2;
}
}
Child component:
@code{
public List<GradeModel> listOfGrades;
[Parameter]
public int PlatformId { get; set; }
protected override async Task OnInitializedAsync()
{
listOfGrades = await gradesService.GetAllGradesAsync(platformId).ConfigureAwait(false);
}
}