I have created a DisplayTemplate for a Comment
class, and placed it inside Comment/DisplayTemplates/Comment.cshtml
.
Comment.cshtml
is properly typed:
@model Comment
Then, I have a partial view that takes an IEnumerable<Comment>
for model. In there I loop through the collection and would like to use the DisplayTemplate for the Comment
class. The view, in its integrity:
@model IEnumerable<Comment>
@foreach (var comment in Model.Where(c => c.Parent == null)) {
@Html.DisplayFor(model => comment)
}
However, I get an error on the Html.DisplayFor
line:
The model item passed into the dictionary is of type 'System.Int32', but this dictionary requires a model item of type 'System.String'.
How can I invoke the DisplayTemplate for each item in the foreach
loop?