Why is my DisplayFor not looping through my IEnumerable<DateTime>?
It's not looping because you have specified a name for the display template as second argument of the DisplayFor
helper (_CourseTableDayOfWeek
).
It loops only when you rely on conventions i.e.
@Html.DisplayFor(m => m.DaysOfWeek)
and then inside ~/Views/Shared/DisplayTemplates/DateTime.cshtml
:
@model DateTime
@{
ViewBag.Title = "CourseTableDayOfWeek";
}
<th>
@System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames[(int) Model.DayOfWeek]
<span class="dateString">Model.ToString("G")</span>
</th>
Once you specify a custom name for the display template (either as second argument of the DisplayFor helper or as [UIHint]
attribute) it will no longer loop for collection properties and the template will simply be passed the IEnumerable<T>
as model.
It's confusing but that's how it is. I don't like it either.