The message is only updated on the second time we click the button that calls DownloadData
@page "/counter"
@using Flurl
@using Flurl.Http
@inject HttpClient Http
<h1>Download Data</h1>
<button @onclick(DownloadData)>Download Data</button>
<p><b>@message</b></p>
@functions {
string message = "";
async void DownloadData()
{
try
{
var url = "https://nnnn.azurewebsites.net/api/PegaOcorrencias/?code=kjsdfklhsdf";
var result = await Http.GetJsonAsync<List<Newtonsoft.Json.Linq.JObject>>(url);
message = "Items count " + result.Count;
}
catch (Exception ex)
{
message = ex.ToString();
}
}
}
@onclickAsync
isn't implemented yet, you'd need to call StateHasChanged()
at the end of the function call to notify the component to update it's State for now. Or you could do it this way as well.
@onclick( async () => await DownloadData())
async Task DownloadData() {
//...
}
Thanks for answering, @RyoukoKonpaku!
Most helpful comment
@onclickAsync
isn't implemented yet, you'd need to callStateHasChanged()
at the end of the function call to notify the component to update it's State for now. Or you could do it this way as well.