Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor Sections: How to update `SectionOutlet` in `MainLayout`?

$
0
0

There is a new feature called Sections in Blazor 8, and I want to use it for my Blazor Web App. I want to update a value changed in a page, but shown in a SectionOutlet in MainLayout. So I inserted a SectionOutlet in the MainLayout.razor:

<div class="top-row px-4"><SectionOutlet SectionName="s-test"></SectionOutlet><a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a></div>

My page for changing the value looks like

@page "/changedata"@rendermode InteractiveServer<SectionContent SectionName="s-test">    @_clickCounter</SectionContent><SectionContent SectionName="s-test-local">    @_clickCounter</SectionContent><button @onclick="ButtonClick">Click</button><SectionOutlet SectionName="s-test-local"></SectionOutlet>@code {    private int _clickCounter = 0;    private void ButtonClick()    {        _clickCounter++;    }}

The value should be shown in two SectionOutlets: one local within the same page called "s-test-local", and another in MainLayout defined in the snippet above (named "s-test").

After a click on the button the current page is updated with the new value, the local Section works. But the Section in the MainLayout shows only the initial value 0, it is only rendered once.

How can I update the SectionOutlet in MainLayout after every button click as well? With this new feature I assumed, things like CascadingValues or EventCallbacks are not neccessary anymore. Do I use an inappropriate rendermode? What am I doing wrong here?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>