好像有什么变了。检查 MVC 3 源代码,我发现它prop.HideSurroundingHtml
用于确定何时打印周围的 HTML,而不是仅打印隐藏元素。以下模板允许为对象图呈现多个级别的编辑器:
@if (ViewData.TemplateInfo.TemplateDepth > 2)
{
@(ViewData.ModelMetadata.Model != null ?
ViewData.ModelMetadata.SimpleDisplayText :
ViewData.ModelMetadata.NullDisplayText)
}
else
{
foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !ViewData.TemplateInfo.Visited(pm)))
{
if (!prop.HideSurroundingHtml)
{
if (!String.IsNullOrEmpty(Html.Label(prop.PropertyName).ToHtmlString()))
{
<div class="editor-label">@Html.Label(prop.PropertyName)</div>
}
@Html.Raw("<div class=\"editor-field\">")
}
@Html.Editor(prop.PropertyName)
if (!prop.HideSurroundingHtml)
{
@Html.ValidationMessage(prop.PropertyName, "*")
@Html.Raw("</div>")
}
}
}