@using Microsoft.AspNetCore.Blazor.Browser.Services.Temporary
@inject HttpClient Http
Weather forecast
This component demonstrates fetching data from the server.
@if (forecasts == null)
{
Loading...
}
else
{
| Date |
Temp. (C) |
Temp. (F) |
Summary |
@foreach (var forecast in forecasts)
{
| @forecast.DateFormatted |
@forecast.TemperatureC |
@forecast.TemperatureF |
@forecast.Summary |
}
}
@functions {
WeatherForecast[] forecasts;
protected override async Task OnInitAsync()
{
var json = await Http.GetStringAsync("/sample-data/weather.json");
forecasts = Microsoft.AspNetCore.Blazor.Json.Deserialize(json);
}
class WeatherForecast
{
public string DateFormatted { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF { get; set; }
public string Summary { get; set; }
}
}