Skip to content

Async function: The message is only updated on the second time we click the button #16301

@TonyHenrique

Description

@TonyHenrique

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();
    }

}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions