Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to call C# function from javascript in the new Blazor .NET 8 Web App Template Auto (Server and WebAssembly)

$
0
0

This is my JavaScript function in app.js that when window is resizing it call c# function that log a message in console

window.addEventListener('resize', function () {    DotNet.invokeMethodAsync("BlazorTest.Client", "SeyHello")});

and this is my C# function

[JSInvokable]public static void SeyHello(){    Console.WriteLine("Hello form js");}

and this is my project template and the Interactive render mode is Auto (Server and WebAssembly)

enter image description here

Question1: where should I put app.js because we have two wwwroot in this project

Question2: if I put app.js in BlazorTest.Client how to reference it to App.razor in BlazorTest

Question3: where should I put my c# function in BlazorTest or BlazorTest.Client

Question4: in razor file that I placed my c# function what is the @rendermode should it be

Finally: I need the code that work in the new Blazor .NET 8 Web App Template


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>