Live Chat Icon For mobile
Live Chat Icon

How do I call a JavaScript method with parameters in Blazor WebAssembly?

Platform: Blazor| Category : JavaScript Interop, General

You call a JavaScript function with parameters using JavaScript Interop.

Syntax:

JsRuntime.InvokeVoidAsync("JS method name", "parameters");

Follow this code to call a JavaScript method with parameters in Blazor WebAssembly

[Index.razor]

@page "/"
@inject IJSRuntime JsRuntime

@code {
    protected override async void OnInitialized()
    {
        string content = "JavaScript function called with parameter";
        await JsRuntime.InvokeVoidAsync("jsFunction", content);
    }
}

[index.html]

<body> 
      . . . 
      . . . 

   <script>
        function jsFunction(value) {
            // Parameter value has been passed here.
            console.log(value);
        };
    </script>
</body >

Refer to this documentation for more information.

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.