I'm following the Microsoft tutorial on Blazor. I'm getting the 'HttpClient doesn't contain a definition for 'GetFromJsonAsync' error when trying to use this extension method in the Index.razor
page. System.Net.Http.Json (v. 6.0.0)
is installed.
This is what my Index.razor file looks like:
@page "/"@using System.Net.Http.Json<div class="main"><h1>Blazing Pizzas</h1><ul class="pizza-cards"> @if (specials != null) { @foreach (var special in specials) {<li style="background-image: url('@special.ImageUrl')"><div class="pizza-info"><span class="title">@special.Name</span> @special.Description<span class="price">@special.GetFormattedBasePrice()</span></div></li> } }</ul></div>@code{ // List of special offers List<PizzaSpecial> specials = new(); protected override async Task OnInitializedAsync() { specials = await HttpClient.GetFromJsonAsync<List<PizzaSpecial>>(NavigationManager.BaseUri +"specials"); }}
I've tried installing a newer version of System.Net.Http.Json
but the error persisted.