How to inject in blazor code behind .razor.cs file? IJSRuntime for example

In the code behind razor.cs file, IJSRunTime or others can be injected with the [Inject] attribute

public partial class BillingDashboard
{
    [Inject]
    IJSRuntime JSRuntime { get; set; }

    protected override async Task MyFunction()
    {
         await JSRuntime.InvokeVoidAsync("console.log('test')");
    }
}

Leave a Comment