Description
Hey Guardrex!
There is a known issue of Cascading Parameters being null which is detailed here: dotnet/aspnetcore#50724
The ThemeInfo sample on this page, does in fact work to pass a CascadingValue down to the ThemedComponent page.
However, the counter on the page is broken as the page is "static" and there is no interactivity such as clicking on the button.
If I then add @attribute [RenderModeInteractiveServer] to fix the issue with the button, (which does fix it) the Cascading Value stops working.
Thus, the sample is not useful. It leads the reader to believe that the CascadingValue will work, but it will in fact not work except on a static page which is unlikely if you are trying to style a button.
As I understand it, the fix is to add this line to program.cs:
builder.Services.AddCascadingValue((str) => new ThemeInfo() { ButtonClass = "btn-primary" });
and then the code and markup can be removed from MainLayout.`
I would recommend updating the Documentation to reflect this.
Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/components/cascading-values-and-parameters?view=aspnetcore-7.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/components/cascading-values-and-parameters.md
Document ID
5fe884b8-51e1-1b91-57f8-522ff0b7890c
Article author
guardrex
Description
Hey Guardrex!
There is a known issue of Cascading Parameters being null which is detailed here: dotnet/aspnetcore#50724
The ThemeInfo sample on this page, does in fact work to pass a CascadingValue down to the ThemedComponent page.
However, the counter on the page is broken as the page is "static" and there is no interactivity such as clicking on the button.
If I then add
@attribute [RenderModeInteractiveServer]to fix the issue with the button, (which does fix it) the Cascading Value stops working.Thus, the sample is not useful. It leads the reader to believe that the CascadingValue will work, but it will in fact not work except on a static page which is unlikely if you are trying to style a button.
As I understand it, the fix is to add this line to program.cs:
builder.Services.AddCascadingValue((str) => new ThemeInfo() { ButtonClass = "btn-primary" });and then the code and markup can be removed from MainLayout.`
I would recommend updating the Documentation to reflect this.
Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/components/cascading-values-and-parameters?view=aspnetcore-7.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/components/cascading-values-and-parameters.md
Document ID
5fe884b8-51e1-1b91-57f8-522ff0b7890c
Article author
guardrex