0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Blazor WebAssemblyでAPIから取得した値を設定しても画面に反映されない場合

Posted at

実装

StateHasChanged() 関数を呼び出してUIを更新してやることで表示されます。

<p class="place_p">@officeName</p>
private string? bookName = "";
private async void GetBookName(string Code)
{
    // API経由でデータ取得
    var list = await Http.GetFromJsonAsync<List<Book>>($"api/books/all/first?id={Code}");
    
    if(list != null && list.Count > 0)
    {
        // ↓ここでは「手を伸ばせ、そしてコマンドを入力しろ」が取得できるとする
        bookName = list[0].officeName == null ? "" : list[0].officeName ;
        // ↓UIの手動更新をトリガーすることで画面に表示される
        StateHasChanged();
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?