Search code examples
c#asp.netrazorblazor

EventCallback as CascadingValue in Razor components using @Body?


I do not seem to be able to supply a callback from the parent component to the child, when teh child is rnedered using @Body:

    <CascadingValue  Value="isGB">
        <CascadingValue Value="HandleChange">
            @Body
        </CascadingValue>
    </CascadingValue>
    </div>

@code {
    private void HandleChange(bool isgb)
    {
        throw new Exception();

        isGB = isgb;
        StateHasChanged();
    }
}

What I ave in the child component:

    [CascadingParameter]
    public EventCallback<bool> HandleChange { get; set; }

    private async Task ChangeIsGB(bool isgb)
    {
        IsGB = isgb;
        await HandleChange.InvokeAsync(isgb);
    }

But the event does not fire, sadly enough. Why?


Solution

  • Actually, setting the rendermode in App.razor solved teh issue. I read that without this events would not fire. (Not even click events)

    This is it:

     <Routes @rendermode=RenderMode.InteractiveServer />
    

    This essentially sets the rendermode to interactiev server by default. Otherwise teh default rendermode is static.