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.
 
 
 
 

62 lines
1.7 KiB

  1. @page "/weather"
  2. <h1>Weather</h1>
  3. <p>This component demonstrates showing data.</p>
  4. @if (forecasts == null)
  5. {
  6. <p><em>Loading...</em></p>
  7. }
  8. else
  9. {
  10. <table class="table">
  11. <thead>
  12. <tr>
  13. <th>Date</th>
  14. <th>Temp. (C)</th>
  15. <th>Temp. (F)</th>
  16. <th>Summary</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. @foreach (var forecast in forecasts)
  21. {
  22. <tr>
  23. <td>@forecast.Date.ToShortDateString()</td>
  24. <td>@forecast.TemperatureC</td>
  25. <td>@forecast.TemperatureF</td>
  26. <td>@forecast.Summary</td>
  27. </tr>
  28. }
  29. </tbody>
  30. </table>
  31. }
  32. @code {
  33. private WeatherForecast[]? forecasts;
  34. protected override async Task OnInitializedAsync()
  35. {
  36. // Simulate asynchronous loading to demonstrate a loading indicator
  37. await Task.Delay(500);
  38. var startDate = DateOnly.FromDateTime(DateTime.Now);
  39. var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
  40. forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
  41. {
  42. Date = startDate.AddDays(index),
  43. TemperatureC = Random.Shared.Next(-20, 55),
  44. Summary = summaries[Random.Shared.Next(summaries.Length)]
  45. }).ToArray();
  46. }
  47. private class WeatherForecast
  48. {
  49. public DateOnly Date { get; set; }
  50. public int TemperatureC { get; set; }
  51. public string? Summary { get; set; }
  52. public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
  53. }
  54. }