You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
859 B
36 lines
859 B
@page "/call-js-example-3"
|
|
@inject IJSRuntime JS
|
|
|
|
<h1>Call JS Example 3</h1>
|
|
|
|
<p>
|
|
<button @onclick="SetStock">Set Stock</button>
|
|
</p>
|
|
|
|
@if (stockSymbol is not null)
|
|
{
|
|
<p>@stockSymbol price: @price.ToString("c")</p>
|
|
}
|
|
|
|
@if (result is not null)
|
|
{
|
|
<p>@result</p>
|
|
}
|
|
|
|
@code {
|
|
private Random r = new();
|
|
private string? stockSymbol;
|
|
private decimal price;
|
|
private string? result;
|
|
|
|
private async Task SetStock()
|
|
{
|
|
stockSymbol =
|
|
$"{(char)('A' + r.Next(0, 26))}{(char)('A' + r.Next(0, 26))}";
|
|
price = r.Next(1, 101);
|
|
var interopResult =
|
|
await JS.InvokeAsync<string>("displayTickerAlert2", stockSymbol, price);
|
|
result = $"Result of TickerChanged call for {stockSymbol} at " +
|
|
$"{price.ToString("c")}: {interopResult}";
|
|
}
|
|
} |