I have the following code:
@model IEnumerable<SampleMvcApp.Models.Exercise>
@foreach (var item in Model.GroupBy(m => m.DayName).Distinct())
{
<table class="table">
<h2>@Html.Display(item.Select(x => x.DayName).ToString())</h2>
<thead>
<tr>
<th>
ExerciseName
</th>
<th>
ExerciseTime
</th>
<th>
ExerciseRepetition
</th>
<th>
MomentOfTheDay
</th>
<th>
Routine
</th>
<th>
Week
</th>
</tr>
</thead>
@foreach (var test2 in item)
{
<tbody>
<tr>
<td>
@Html.DisplayFor(modelItem => test2.ExerciseName)
</td>
<td>
@Html.DisplayFor(modelItem => test2.ExerciseTime)
</td>
<td>
@Html.DisplayFor(modelItem => test2.ExerciseRepetition)
</td>
<td>
@Html.DisplayFor(modelItem => test2.MomentOfTheDay)
</td>
<td>
@Html.DisplayFor(modelItem => test2.Routine.RoutineID)
</td>
<td>
@Html.DisplayFor(modelItem => test2.ExerciseWeek)
</td>
<td>
<a asp-action="Edit" asp-route-id="@test2.ExerciseID">Edit</a> |
<a asp-action="Details" asp-route-id="@test2.ExerciseID">Details</a> |
<a asp-action="Delete" asp-route-id="@test2.ExerciseID">Delete</a>
</td>
</tr>
</tbody>
}
</table>
}
Everything works fine but
<h2>@Html.Display(item.Select(x => x.DayName).ToString())</h2>
I'm just trying to show the Day Name above the table as it is grouped by days, however the Display code won't show anything. I've tried using DisplayFor but apparently it doesn't accept expressions. Or maybe I am doing it wrong.