user1384117
user1384117

Reputation: 81

How to use Blazored.LocalStorage in a Blazor code behind file

All the examples I can find show how to use it in the razor file like this:

@page "/"

@inject Blazored.LocalStorage.ILocalStorageService localStorage

I would like to move it to a Base file (code behind file) but nothing I try seems to work

I tried :

  public class SomeClassBase : ComponentBase
  {

    [Inject]
    public blazored.LocalStorage.ILocalStorageService;

but this did not work.

Any help from someone who is not going to answer with "Why do you want to do this" would be very much appreciated. Thank you.

Upvotes: 0

Views: 1139

Answers (1)

enet
enet

Reputation: 45596

Did you try something like this:

[Inject]
public blazored.LocalStorage.ILocalStorageService localStorage { get; set;}

As far as I recall you should use a property rather than a field. Try it.

Upvotes: 1

Related Questions