-
Notifications
You must be signed in to change notification settings - Fork 50
Parameters with non-public accessors are not set #115
Comments
Cascading parameters are supported. Could you create a minimal reproduction to show the exact issue? Keep in mind that you need to declare such parameters in both the component and the view model in order to make this work. Have a look at the Readme for some examples regarding parameters. |
Hi,
and here is my ViewModel code:
In this line of code: var a = authenticationState.Result, authenticationState is null. |
Can you confirm that the property has a value in the component itself? |
I have added initialization in my component, like this:
In component, I receive result from authenticationState.Result, however, now my BindingContext is null. I'm guessing that it is because I have OnInitialize in both component and ViewModel. When I leave OnInitialize methot only on component it works fine, but I need it inside ViewModel. Do you have any idea how to resolve this. |
If you override I would still assume that your authentication state is simply null in the first place. Please review the docs and ensure that you properly set up your router. |
@bojankostic81 try changing the visibility to public (on both the component and view model), then I believe it should work. |
@hrannzo good catch, does parameter injection into components work without a public setter? If so, such a use case should be supported by this library. |
@klemmchr It seems that a property can be private but it must have a setter defined when receiving a cascading value. The setter can be private and init. If the setter is missing then an exception is thrown from the belly of the Blazor. CascadingComponent.razor
WrapperComponent.razor
|
@hrannzo thanks for the investigation, this actually is a bug in the library |
Question
Hi,
How can I get AuthenticationState in ViewModel? I'm trying with:
[CascadingParameter] Task AuthenticationState { get; set; }
but it is always null.
Thanks.
Code sample
No response
Version
6.0.6
Are you using Blazor WASM or Blazor Server?
Blazor WASM
The text was updated successfully, but these errors were encountered: