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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…