PWA Fundvelo der Caritas.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FetchData.razor 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. @page "/fetchdata"
  2. @inject HttpClient Http
  3. <h1>Weather forecast</h1>
  4. <p>This component demonstrates fetching data from the server.</p>
  5. @if (forecasts == null)
  6. {
  7. <p><em>Loading...</em></p>
  8. }
  9. else
  10. {
  11. <table class="table">
  12. <thead>
  13. <tr>
  14. <th>Date</th>
  15. <th>Temp. (C)</th>
  16. <th>Temp. (F)</th>
  17. <th>Summary</th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. @foreach (var forecast in forecasts)
  22. {
  23. <tr>
  24. <td>@forecast.Date.ToShortDateString()</td>
  25. <td>@forecast.TemperatureC</td>
  26. <td>@forecast.TemperatureF</td>
  27. <td>@forecast.Summary</td>
  28. </tr>
  29. }
  30. </tbody>
  31. </table>
  32. }
  33. @code {
  34. private WeatherForecast[] forecasts;
  35. protected override async Task OnInitializedAsync()
  36. {
  37. forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
  38. }
  39. public class WeatherForecast
  40. {
  41. public DateTime Date { get; set; }
  42. public int TemperatureC { get; set; }
  43. public string Summary { get; set; }
  44. public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
  45. }
  46. }