mirror of
https://github.com/PacktPublishing/Web-Development-with-Blazor-Second-Edition.git
synced 2025-12-06 05:32:03 +01:00
16 lines
453 B
Plaintext
16 lines
453 B
Plaintext
|
|
@page "/nettojs"
|
||
|
|
@inject IJSRuntime jsRuntime
|
||
|
|
|
||
|
|
<h3>This is a demo how to call JavaScript from .NET</h3>
|
||
|
|
|
||
|
|
|
||
|
|
<button @onclick="ShowAlert">Show Alert</button>
|
||
|
|
@code {
|
||
|
|
protected async void ShowAlert()
|
||
|
|
{
|
||
|
|
IJSObjectReference jsRef = await jsRuntime.InvokeAsync<IJSObjectReference>("import", "/_content/Components/Pages/JSInteropSamples/NetToJS.razor.js");
|
||
|
|
|
||
|
|
await jsRef.InvokeVoidAsync("showAlert", "Hello from .NET");
|
||
|
|
}
|
||
|
|
}
|