I created a new Blazor app and I want to access a URL through HttpClient I faced this error
'HttpClient' does not contain a definition for 'GetFromJsonAsync' and no accessible extension method 'GetFromJsonAsync' accepting a first argument of type 'HttpClient' could be found (are you missing a using directive or an assembly reference?) [BlazorApp]csharp(CS1061) ,
this is my code
@inject HttpClient Http
<h1>@name</h1>
@code {
private string name;
protected override async Task OnInitializedAsync()
{
name = await Http.GetFromJsonAsync<string>("api/");
}
}
You need to add the following using directive:
using System.Net.Http.Json;
GetFromJsonAsync
is an extension method, not part of HttpClient
itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With