Call static .NET methods from JavaScript functions in Blazor

DotNet.invokeMethodAsync('{ASSEMBLY NAME}', '{.NET METHOD ID}', {ARGUMENTS});
  • The {ASSEMBLY NAME} placeholder is the app’s assembly name.
  • The {.NET METHOD ID} placeholder is the .NET method identifier.
  • The {ARGUMENTS} placeholder are optional, comma-separated arguments to pass to the method, each of which must be JSON-serializable.
@page "/call-dotnet-example-1"

<h1>Call .NET Example 1</h1>

    <button onclick="returnArrayAsync()">
        Trigger .NET static method

@code {
    public static Task<int[]> ReturnArrayAsync()
        return Task.FromResult(new int[] { 1, 2, 3 });
  window.returnArrayAsync = () => {
    DotNet.invokeMethodAsync('BlazorSample', 'ReturnArrayAsync')
      .then(data => {