I'm learning ASP.NET MVC 4. Some of the default template views contain something like this:
@model IEnumerable<SomeModel>
...
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Property1)
</td>
<td>
@Html.DisplayFor(modelItem => item.Property2)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
@Html.ActionLink("Details", "Details", new { id=item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id=item.Id })
</td>
</tr>
}
My understanding is that the DisplayFor
takes an expression where the input parameter is the view's Model and the return value is any object, and finds the appropriate DisplayTemplate for the returned object.
Based on this, I can see why DisplayFor(modelItem => item.Property1)
works, but it doesn't feel like the right choice. If I'm not using the modelItem
parameter at all, why use DisplayFor
? Is there no method like GetDisplayTemplate(item.Property1)
?