FetchData.razor 1.1 KB

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