This is a demo how to call .NET from JavaScript using a .NET reference
@*
This demo shows how to call a JavaScript method with an instance of a .NET object.
The JavaScript then calls a method on the .NET object.
The JavaScript file JSToReferenceNET.js is included in the _layout/index page.
*@
@result
@code {
private string? name;
private string? result;
private DotNetObjectReference? dotNetHelper;
public async Task TriggerDotNetInstanceMethod()
{
dotNetHelper = DotNetObjectReference.Create(this);
result = await JS.InvokeAsync("callreferencenetfromjs", dotNetHelper);
}
[JSInvokable]
public string GetHelloMessage() => $"Hello, {name}!";
public void Dispose()
{
dotNetHelper?.Dispose();
}
}