Files
ASP.NET-MVC-Study/BlazorApp/BlazorStateApp/Pages/JSInterop.razor

35 lines
668 B
Plaintext
Raw Normal View History

2023-08-25 09:32:32 +09:00
@page "/jsinterop"
@inject IJSRuntime _jsRuntime;
<h3>JSInterop</h3>
<div>
<button type="button" class="btn btn-primary" @onclick="HelloWorld">
Hello World!
</button>
</div>
<br />
<div>
<button type="button" class="btn btn-primary" @onclick="InputName">
Input Name
</button>
<p>@_name</p>
</div>
@code {
string _name;
private async void HelloWorld()
{
await _jsRuntime.InvokeVoidAsync("testFunction.helloWorld", null);
}
private async void InputName()
{
_name = await _jsRuntime.InvokeAsync<string>("testFunction.inputName", "Send from Blazor");
StateHasChanged();
}
}