[英]How to inject in blazor code behind .razor.cs file? IJSRuntime for example
With a normal single page razor component in Blazor.在 Blazor 中使用普通的单页剃刀组件。 I can inject
IJSRuntime
like this at the top of the page:我可以像这样在页面顶部注入
IJSRuntime
:
@inject IJSRuntime JSRuntime
If I create a code behind .razor.cs file for the component, how do I inject something like IJSRuntime
into the code behind file?如果我为组件在 .razor.cs 文件后面创建了一个代码,我如何将
IJSRuntime
之类的IJSRuntime
注入到代码隐藏文件中?
In the code behind razor.cs file, IJSRunTime
or others can be injected with the [Inject]
attribute在razor.cs文件后面的代码中,可以使用
[Inject]
属性注入IJSRunTime
或其他
public partial class BillingDashboard
{
[Inject]
IJSRuntime JSRuntime { get; set; }
protected override async Task MyFunction()
{
await JSRuntime.InvokeVoidAsync("console.log('test')");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.