Instead of having a view that accepts an IEnumerable<Comment> , and all it does is loop through the collection and just call the correct display pattern:
@Html.DisplayFor(x => x.Comments)
where the Comments property is an IEnumerable<Comment> , which automatically loops and displays the Comment.cshtml display Comment.cshtml for each element of this collection.
Or, if you really need that look (I donβt know why), you could simply:
@model IEnumerable<Comment> @Html.DisplayForModel()
As for the Where clause that you use there, you should simply delete it and delegate this task to the controller. The responsibility of the dispatcher is to prepare the presentation model, and not the presentation that performs such tasks.
Darin Dimitrov Apr 13 2018-11-11T00: 00Z
source share