FetchData.razor
1 @page "/fetchdata" 2 @using GradeView.Data 3 @inject WeatherForecastService ForecastService 4 5 <h1>Weather forecast</h1> 6 7 <p>This component demonstrates fetching data from a service.</p> 8 9 @if (forecasts == null) 10 { 11 <p><em>Loading...</em></p> 12 } 13 else 14 { 15 <table class="table"> 16 <thead> 17 <tr> 18 <th>Date</th> 19 <th>Temp. (C)</th> 20 <th>Temp. (F)</th> 21 <th>Summary</th> 22 </tr> 23 </thead> 24 <tbody> 25 @foreach (var forecast in forecasts) 26 { 27 <tr> 28 <td>@forecast.Date.ToShortDateString()</td> 29 <td>@forecast.TemperatureC</td> 30 <td>@forecast.TemperatureF</td> 31 <td>@forecast.Summary</td> 32 </tr> 33 } 34 </tbody> 35 </table> 36 } 37 38 @code { 39 WeatherForecast[] forecasts; 40 41 protected override async Task OnInitAsync() 42 { 43 forecasts = await ForecastService.GetForecastAsync(DateTime.Now); 44 } 45 }