https://www.syncfusion.com/faq/blazor/javascript-interop/how-do-i-call-a-javascript-method-with-parameters-in-blazor-webassembly

https://learn.microsoft.com/en-us/aspnet/core/blazor/javascript-interoperability/?view=aspnetcore-8.0

[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 >

Last modified: October 26, 2024

Author

Comments

Write a Reply or Comment