I have layout defined as such
@layout MainLayout
@inherits LayoutComponentBase
<CascadingValue Value="this">
@Body
@("_total " + _total)
@("_perPage " + _perPage)
</CascadingValue>
@code {
public int _total;
public int _perPage;
}
Then in component receive the layout reference
[CascadingParameter] public Layout Layout { get; set; }
And the set it as such in
protected override async Task OnInitializedAsync()
{
Layout._total = 3;
Layout._perPage = 3;
}
Problem is the values in the Layout
don't get updated. I tried with 'StateHasChanged` after the setter statements but that doesn't seem to make a difference
You are setting the value, but there's nothing driving a StateHasChanged
event in the Layout component. You can:
StateHasChanged
which you call from your component.StateHasChanged
- can get messy!.StateHasChanged
as detailed in Surinder's answer.