I have a side drawer in my MainLayout.razor
component, which is used to set/change certain values which are then used throughout the app.
<CascadingValue Value="@appValues" Name="AppValue">
<SideDrawer OnUpdate="@RefreshPage"></SideDrawer>
<div class="content px-4">
@Body
</div>
</CascadingValue>
When I update the values in the SideDrawer, I do an EventCallback
, through which I can update the variables which can then be used as cascading values throughout the page components.
@code{
public AppValues appValues = new AppValues();
protected void RefreshPage()
{
appValues.value1 = somevaluefromsidedrawer;
appValues.value2 = someothervaluefromsidedrawer;
StateHasChanged();
}
}
And these cascading values get updated just fine in the page components. But the problem is, in the page components, there is a method (let's say LoadData()
) in which certain datasets should be updated based on these cascading values.
@code{
[CascadingParameter(Name = "AppValue")]
protected AppValues appValues { get; set; }
protected void RefreshCurrentPage()
{
LoadData(appValues.value1);
}
}
Ideally, I would like to be able to call the RefreshCurrentPage()
method in the page component from the RefreshPage()
method in the MainLayout.razor
component, so that all the datasets in the page component are refreshed based on the updated values.
Is it possible to do something like this?