In a Blazor Static SSR project, how do interactive components receive a parameter?
I created a simple project on github to demonstrate the problem.
This is a Blazor Static SSR project, with interactive components. In program.cs, it uses:
builder.Services.AddRazorComponents().AddInteractiveServerComponents();
The requirements are: The pages are non-interactive (EditForms with submit). The project cannot have globally available interactivity (such as Blazor Server).
On many pages, we want to include an interactive component.
When a noninteractive page includes an interactive component, Blazor will not let you use the standard method of including a parameter such as: ChildInteractive userid="aaa" ChildInteractive.
The solution seems to be set the parameter in program.csThis is done using:builder.Services.AddCascadingValue("UserID", sp => (string)"Initial value, set in Program.cs");
That Cascading Parameter is available to all components.
(BTW, in a Static SSR project, Cascading Parameters set in Routes.razor are only available to non-interactive components.)
My question is: The cascading parameter is set using builder.Services.AddCascadingValue. But, how do you modify the value? In my case, the parameter is the logon UserID. However, the UserID is not known until the user logs in. Therefore, once the user logs in, the cascading parameter, UserID, needs to be updated.
Sample project:
https://github.com/ssperoniGIT/Blazor-SSR-Params
It seems the only solution is to set the parameter before the projects starts, by setting it in program.cs. But it needs to be updated.