I'm working ASP.NET MVC with Razor pages. When I add items with a ForEach loop the last-child selector works fine. When I use a For loop the last-child does not work.
This works:
    @foreach (var m in Model.Playlists)
    {
        <tr>
            <td><a href="/PlayLists/ShowTracks?playlistId=@m.id&trackCount=@m.TrackCount&playlistName=@m.Name">@m.Name</a></td>
            <td>@m.TrackCount</td>
        </tr>
    }
This does not work:
    @for (int i = 0; i < Model.TrackList.Count; i++)
    {
        <tr>
           <td>@Html.CheckBoxFor(x => x.TrackList[i].IsSelected)</td>
            <td>@Model.TrackList[i].Name)</td>
            <td>@Model.TrackList[i].Artist</td>
            <td>@Model.TrackList[i].Album</td>
         </tr>
            @Html.HiddenFor(x => x.TrackList[i].Artist)
            @Html.HiddenFor(x => x.TrackList[i].id)
            @Html.HiddenFor(x => x.TrackList[i].Album)
            @Html.HiddenFor(x => x.TrackList[i].Name)
        }
As a work around I can add this:
    @if (i == (Model.TrackList.Count - 1))
    {
        <td class="lastright">@Model.TrackList[i].Album</td>
    }
    else
    {
        <td>@Model.TrackList[i].Album</td>
    }
And then add my style to class. Just curious why it doesn't work as expected. The DOM explorer does not show any additional elements.
Also here is the CSS:
    .tracksTable tbody tr:last-child td:first-child {
        border-radius: 0 0 0 16px;
    }
    .tracksTable tbody tr:last-child td:last-child {
        border-radius: 0 0 16px 0;
    }