C#C
C#2y ago
hunterlan

Root - level cascading value and parameter

According to official documentation(https://learn.microsoft.com/en-us/aspnet/core/blazor/components/cascading-values-and-parameters?view=aspnetcore-8.0), I can create a cascading parameter like that:
builder.Services.AddCascadingValue(sp => new CascadingValueSource<UserState>(new UserState(), isFixed: false));
And then use it like that:
[CascadingParameter] public UserState UserState { get; set; }
And our variable UserState shouldn't be null, right?

I have a Blazor Web App project (InteractiveAuto) and unfortunately, UserState for me is null. I called AddCascadingValue to both projects and it's still null. I don't understand what I am doing wrong.
Learn how to flow data from an ancestor Razor component to descendent components.
Was this page helpful?