You can call a JavaScript function with parameters using JavaScript Interop.
Syntax:
JsRuntime.InvokeVoidAsync("JS method name", "parameters");
To call a JavaScript method with parameters in Blazor WebAssembly, you can follow the code snippet provided below:
[Index.razor]
@page "/"
@inject IJSRuntime JsRuntime
<p>Here's an example of how to call a JavaScript method with parameters in Blazor WebAssembly.</p>
@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