First I have a Display Template in Views > Blog > DisplayTemplates:
@model Domain.Model.BlogPost
<div class="blogSummary">
@Html.ActionLink(Model.Title, "post", new { Id = Model.PostID }, new { @class = "titleLink" })
<div class="subInfo">
Posted by @Model.Author on @Model.PostedDate.ToString("D") | @Model.PostComments.Count
Comment(s)</div>
<br />
<div class="summaryText">
@Html.Markdown(Model.Body.Length > 300 ? Model.Body.Remove(0, 300) + "..." : Model.Body)
@Html.ActionLink("(view more)", "post", new { Id = Model.PostID })
</div>
</div>
Then I have a view:
@model IEnumerable<Domain.Model.BlogPost>
@{
ViewBag.Title = "Index";
}
@Html.DisplayFor(x => x, "BlogPostSummary")
However, I am getting an error on the DisplayFor()
:
The model item passed into the dictionary is of type 'System.Data.Objects.ObjectSet`1[Domain.Model.BlogPost]', but this dictionary requires a model item of type 'Domain.Model.BlogPost'.
I'm having a bit of trouble understanding what's going on. What is the best way to use the display template?