I have a partial view, in my ASP.NET MVC4 web app. It's just a partial view designed to display a table, given a collection of entities. It looks like this:
@model ICollection<Portal.Models.Matter>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Last Accessed</th>
<th>Client</th>
</tr>
</thead>
<tbody>
@if (Model.Count > 0)
{
@Html.DisplayForModel()
}
else
{
<tr>
<td colspan="3" class="text-muted text-centered">There are no Matters to display.</td>
</tr>
}
</tbody>
</table>
I have a DisplayTemplate for Matter
that is statically typed to the single Matter
entity, and it handles rendering of each table row.
For some reason, when this partial is rendered, instead of using the Matter
DisplayTemplate it just shows the following:
System.Collections.Generic.List`1[Portal.Models.Account]System.Collections.Generic.List`1[Portal.Models.Account]
Now, this partial is not even bound to a collection of Account
entities. It's bound to a collection of Matter
entities. So, why is @Html.DisplayForModel()
trying to display for a collection of Account
s? At run time, using a debugger, I can see the Model
is in fact a collection of Matter
entities, not Account
.
I render this partial using the following code:
@Html.Partial("~/Views/Matter/_Table.cshtml", Model.Client.Matters, new ViewDataDictionary())