I need to create a table which looks like:
S1 S2 S3 S4 S5
C1 C1S1 C1S2 C1S3 C1S4 C1S5
C2 C2S1 C2S2 C2S3 C2S4 C2S5
C3 C3S1 C3S2 C3S3 C2S4 C3S5
C4 C4S1 C4S2 C4S3 C3S4 C4S5
C5 C5S1 C5S2 C5S3 C4S4 C5S5
but following code:
<table>
@foreach (var client in this.Model.Clients)
{
<tr>
<td >@client.Name</td>
@foreach (var session in this.Model.Sessions)
{
foreach (var data in this.Model.ClientSessions)
{
if (data.ClientId== client.ClientId&& data.SessionId == session.SessionId)
{
<td>@data.TotalClientSessions</td>
}
}
}
</tr>
}
</table>
produce:
//here should be missing header
C1 C1S1 C1S2 C1S3 C1S4 C1S5
C2 C2S1 C2S2 C2S3 C2S4 C2S5
C3 C3S1 C3S2 C3S3 C2S4 C3S5
C4 C4S1 C4S2 C4S3 C3S4 C4S5
C5 C5S1 C5S2 C5S3 C4S4 C5S5
I don't know how to smartly modify this code to get headers. I would add another foreach at the bottom to create header lines this way:
<tr>
<th></th>
@foreach (var session in this.Model.Sessions)
{
<th>@Session.Id</th>
}
</tr>
but I believe, that there is other, more smarter solution to achieve that. Any help will be appreciated.