ASP.NET MVC4 Web アプリに部分的なビューがあります。これは、エンティティのコレクションが与えられたテーブルを表示するように設計された、単なる部分的なビューです。次のようになります。
@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>
Matter単一のエンティティに静的に型付けされた DisplayTemplate がMatterあり、各テーブル行のレンダリングを処理します。
何らかの理由で、このパーシャルがレンダリングされると、MatterDisplayTemplate を使用する代わりに次のように表示されます。
System.Collections.Generic.List`1[Portal.Models.Account]System.Collections.Generic.List`1[Portal.Models.Account]
現在、このパーシャルはAccountエンティティのコレクションにバインドされていません。Matterエンティティのコレクションにバインドされています。では、なぜ@Html.DisplayForModel()のコレクションを表示しようとしているAccountのですか? 実行時にデバッガーを使用すると、 が実際にはエンティティModelのコレクションであり、 ではないことがわかります。MatterAccount
次のコードを使用して、このパーシャルをレンダリングします。
@Html.Partial("~/Views/Matter/_Table.cshtml", Model.Client.Matters, new ViewDataDictionary())