mirror of
https://github.com/PacktPublishing/Web-Development-with-Blazor-Second-Edition.git
synced 2026-04-06 14:53:48 +00:00
Initial commit
This commit is contained in:
parent
2190113c56
commit
3088165398
1765 changed files with 192085 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
|||
@page "/jstostaticnetwasm"
|
||||
@using System.Runtime.InteropServices.JavaScript
|
||||
|
||||
<h3>This is a demo how to call .NET from JavaScript</h3>
|
||||
|
||||
<button @onclick="ShowMessage">Show alert with message</button>
|
||||
|
||||
@code {
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await JSHost.ImportAsync("jstonet", "../JSInteropSamples/JSToStaticNET.razor.js");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
using System.Runtime.InteropServices.JavaScript;
|
||||
using System.Runtime.Versioning;
|
||||
namespace BlazorWebAssembly.Client.JSInteropSamples;
|
||||
|
||||
[SupportedOSPlatform("browser")]
|
||||
public partial class JSToStaticNET
|
||||
{
|
||||
[JSExport]
|
||||
internal static string GetAMessageFromNET()
|
||||
{
|
||||
return "This is a message from .NET";
|
||||
}
|
||||
|
||||
[JSImport("showMessage", "jstonet")]
|
||||
internal static partial void ShowMessage();
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
export async function setMessage() {
|
||||
const { getAssemblyExports } = await globalThis.getDotnetRuntime(0);
|
||||
var exports = await getAssemblyExports("BlazorWebAssembly.Client.dll");
|
||||
alert(exports.BlazorWebAssembly.Client.JSInteropSamples.JSToStaticNET.GetAMessageFromNET());
|
||||
}
|
||||
|
||||
export async function showMessage() {
|
||||
await setMessage();
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
@page "/nettojswasm"
|
||||
@using System.Runtime.InteropServices.JavaScript
|
||||
|
||||
<h3>This is a demo how to call JavaScript from .NET</h3>
|
||||
|
||||
<button @onclick="ShowAlert">Show Alert</button>
|
||||
@code {
|
||||
protected async void ShowAlert()
|
||||
{
|
||||
ShowAlert("Hello from .NET");
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await JSHost.ImportAsync("nettojs", "../JSInteropSamples/NetToJS.razor.js");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
using System.Runtime.InteropServices.JavaScript;
|
||||
namespace BlazorWebAssembly.Client.JSInteropSamples;
|
||||
public partial class NetToJS
|
||||
{
|
||||
[JSImport("showAlert", "nettojs")]
|
||||
internal static partial string ShowAlert(string message);
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export function showAlert(message) {
|
||||
return alert(message);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue