Share via

[InjectAttribute] in VIew Model class

biprism 51 Reputation points
2022-05-15T20:10:38.067+00:00

I injected the NavigationManager in my view Blazor Razor component and is available to use it. I'm calling from View a method in VIewModel that needs to use NavigationManager. I used [Inject] attribute to initialize the NavigationManager public property, but it is not getting injected.

One approach is to pass NaviagtionManger to VIewModel or set the navigationmanager property in VIewModel from View.
Is there a different better way to do it?

a.Razor Injects the NaviagtionManagaer using @Inject and is available within the view.
aViewModel.cs tries to Inject the NaviagtionManager and is not doing it and is not available.

Developer technologies | .NET | Blazor

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.