Adding a Forecast Class

Learn how to fetch data from OpenWeather One Call API and display it on the page.

We need to add a Forecast class to capture the results from the OpenWeather One Call API. We will do this by following these steps:

  1. Return to Visual Studio.
  2. Right-click the Models folder and select the “Add, Class” option from the menu.
  3. Name the new class OpenWeather.
  4. Add the following classes:
Press + to interact
public class OpenWeather
{
public Daily[] Daily { get; set; }
}
public class Daily
{
public long Dt { get; set; }
public Temp Temp { get; set; }
public Weather[] Weather { get; set; }
}
public class Temp
{
public double Min { get; set; }
public double Max { get; set; }
}
public class Weather
{
public string Description { get; set; }
public string Icon { get; set; }
}

The preceding classes will be used with the OpenWeather One Call API.

Adding a DailyForecast component

We need a component to display each day’s forecast. We will do this by following these steps:

  1. Right-click the Shared folder and select the “Add, Razor Component” option from the menu.
  2. Name the new component DailyForecast.
...