Tôi có dòng này trong quan điểm của tôiTại sao DisplayFor không lặp lại thông qua IEnumerable <DateTime> của tôi?
@(Html.DisplayFor(m => m.DaysOfWeek, "_CourseTableDayOfWeek"))
nơi m.DaysOfWeek
là một IEnumerable<DateTime>
.
Có nội dung của _CourseTableDayOfWeek.cshtml:
@model DateTime
@{
ViewBag.Title = "CourseTableDayOfWeek";
}
<th>
@System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames[(int) Model.DayOfWeek]
<span class="dateString">Model.ToString("G")</span>
</th>
Và tôi nhận được lỗi sau:
The model item passed into the dictionary is of type '
System.Collections.Generic.List`1[System.DateTime]
', but this dictionary requires a model item of type 'System.DateTime
'.
Nếu tôi tham khảo các bài sau:
https://stackoverflow.com/a/5652524/277067
Các DisplayFor
nên lặp qua IEnum có thể xóa và hiển thị mẫu cho mỗi mục, phải không?
Ok, thật đáng buồn, cảm ơn –
Ditto. Một khía cạnh khác của những người trợ giúp khó gỡ lỗi và hoàn toàn không rõ ràng. – core24
Tôi chỉ rơi vào cùng một cái bẫy.Điều này có vẻ hoàn toàn phản trực giác với tôi. Tôi hy vọng điều này sẽ thay đổi với MVC 4. –