I found this Related Topic, but it failed to answer my question.
When automatically creating a strongly typed view, lets say with a List scaffolding template, I will get something roughly like this:
@model IEnumerable<Test.Models.abc>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.ID)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.ID)
</td>
</tr>
}
</table>
I understand @Html.DisplayNameFor(model => model.ID) completely, but not @Html.DisplayFor(modelItem => item.ID).
What is the purpose of modelItem? Replacing it with any arbitrary text will result in a functional web page. It seems that modelItem is just a throwaway word. I guess my real question is why doesn't this work?
@Html.DisplayFor(item => item.ID)
Edit
A good point was brought up in the comments. It seems you are also able to change model to anything so long as you change it on both sides of the lambda expression:
@Html.DisplayNameFor(abc => abc.ID)
A side question would be: How does the @model statement at the top affect the functions below? I had previously thought model referenced the @model expression in order to figure out the display name via the class, but the page still works after the mentioned changes.