This seems to be the intended behavior for Display / EditorTemplates, supposedly to prevent accidental infinite recursion in custom display templates such as execution (in Item.cshtml ):
@model Item @Html.DisplayFor(x => x)
... which will display Item.cshtml DisplayTemplate endlessly.
Obviously, in your example, you are passing an element / model to another template, so this will not result in infinite recursion. However, he still seems to be in the same safe guard. Not quite sure if it will be classified as a “mistake” or just “by design”?
This is a check in DisplayFor / TemplateFor helper :
ViewData.TemplateInfo.VisitedObjects stores visited objects / models for parent templates. At startup:
@Html.DisplayFor(x => x.Items[i], new { RowPosition = i})
It displays your Item.cshtml DisplayTemplate and adds the item / model to VisitedObjects . This means that when Item.cshtml tries to display another child template with the same element / model:
@Html.DisplayFor(x => x, "ItemDetails")
The element / model is already in VisitedObjects , so the if statement returns true, and instead of rendering ItemDetails.cshtml it simply silently returns / displays an empty string.
source share