Blazor 'Global' Parameter - passing between MainLayout.razor , NavMenu.razor, Counter.razor - back and forth

前端 未结 3 445
天命终不由人
天命终不由人 2021-01-14 17:34

Given a \'default\' Blazor app - created using the Visual Studio 2019 Blazor server template. How do you create a GLOBAL object that is acc

3条回答
  •  -上瘾入骨i
    2021-01-14 17:58

    There is two ways of doing this.

    CascadingParameter and "State Container" that are very well explained in this article.

    Between CascadingParameter and "State Container", you are the one that should know how your application works and decide what to do.

    Probably state container would be better for something like GLOBAL object that is accessible from all the razor pages and components.

    Use [Parameters]?

    Instead of passing all parameters down to components, you should use CascadingParameter

    Create a Static Class ?

    Instead of creating a static class, you should use "State Container"

提交回复
热议问题