I have a crude weather dashboard built with ASP.NET Core and C# (MVC). Right now I have the View displaying the data from the API Call by means of a foreach loop:
@foreach (var forecast in Model.list)
{
<tr>
<td>@(TimeUtils.UnixTimeStampToDateTime(forecast.dt).ToLongDateString())</td>
<td>@forecast.main.temp_min F°</td>
<td>@forecast.main.temp_max F°</td>
<td>@forecast.main.temp F°</td>
<td>@forecast.main.feels_like</td>
</tr>
}
The data I want to display from the API call is stored in a list in the model:
public class CityModel
{
public List<List> list { get; set; }
}
This list has weather data for every 3 hours over a 5 day period. When the foreach loop finishes iterating over the List data, it displays total of 40 entries in the table.
Weather forecast for Enid
date min max temp feels_like
Monday, October 18, 2021 68.99 F° 69.85 F° 68.99 F° 67.37
Monday, October 18, 2021 70.16 F° 72.52 F° 70.16 F° 68.52
Monday, October 18, 2021 66.36 F° 67.24 F° 67.24 F° 65.41
Monday, October 18, 2021 63.55 F° 63.55 F° 63.55 F° 61.54
Tuesday, October 19, 2021 60.76 F° 60.76 F° 60.76 F° 58.8
Tuesday, October 19, 2021 59.74 F° 59.74 F° 59.74 F° 57.76
cont...
What I would like to know is how would I go about getting the table to display only every 8th entry/ index (making it, in effect, a daily forecast) as opposed to every entry/index? I gather it would somehow involve using the condition:
if( index % 8 == 0) {
<tr>
<td>@(TimeUtils.UnixTimeStampToDateTime(forecast.dt).ToLongDateString())</td>
<td>@forecast.main.temp_min F°</td>
<td>@forecast.main.temp_max F°</td>
<td>@forecast.main.temp F°</td>
<td>@forecast.main.feels_like</td>
</tr>
}
but beyond this, I'm in the dark.