When my view appears I see the data for the AdminDetails records but there is no formatting for <tr> and <td> I also don't see any x's. I am using areas and the code for the view is inside an area. Is it possible that my code is not getting the DisplayTemplate because I am using areas?

Here's an example of the way data appears:

<table>

<thead>

<tr>

<th><label for="">Order</label></th>

<th><label for="">Order</label></th>

<th><label for="">Level</label></th>

<th><label for="">Title</label></th>

<th><label for="">Status</label></th>

</tr>

</thead>

<tbody>

<div class="display-label">PartitionKey</div>

<div class="display-field">01</div>

<div class="display-label">RowKey</div>

<div class="display-field">02</div>

<div class="display-label">Title</div>

<div class="display-field">Test55</div>

<div class="display-label">Status</div>

<div class="display-field">New</div>

<div class="display-label">Type</div>

<div class="display-field"></div>

<div class="display-label">Level</div>

<div class="display-field"></div>

网友答案:

The path to your display template is wrong. Instead of:

Views\DisplayTemplates\AdminDetail.cshtml

you should use:

Views\Shared\DisplayTemplates\AdminDetail.cshtml

Notice the Shared bit. It could also be:

Views\XXX\DisplayTemplates\AdminDetail.cshtml

where XXX is the name of the current controller if you want this display template to be available only for this controller.

Also replace your loop:

@foreach (var item in Model)
{
@Html.DisplayFor(model => item)
}

with its equivalent:

@Html.DisplayForModel()

You don't need to loop. Since your model is a collection, ASP.NET MVC will automatically invoke your display template for each element of this collection.