@page "/fetchdata"
Weather forecast
@using BlazorServer.Data
@inject WeatherForecastService ForecastService
Weather forecast
This component demonstrates fetching data from a service.
@if (forecasts == null)
{
Loading...
}
else
{
Date |
Temp. (C) |
Temp. (F) |
Summary |
@foreach (var forecast in forecasts)
{
@forecast.Date.ToShortDateString() |
@forecast.TemperatureC |
@forecast.TemperatureF |
@forecast.Summary |
}
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}
}