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