这似乎为编辑模板工作的引导,请让我知道的任何改进
Object.cshtml
@if (Model == null)
{
@ViewData.ModelMetadata.NullDisplayText
}
else if (ViewData.TemplateInfo.TemplateDepth > 1)
{
@ViewData.ModelMetadata.SimpleDisplayText
}
else
{
foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForDisplay && !ViewData.TemplateInfo.Visited(pm)))
{
if (prop.HideSurroundingHtml)
{
@Html.Editor(prop.PropertyName)
}
else
{
@Html.Label(prop.PropertyName, new { @class = "control-label col-md-2", @style = "text-align:right;" })
@Html.Editor(prop.PropertyName, null, new { @class = "form-control " })
@Html.ValidationMessage(prop.PropertyName, "", new { @class = "text-danger" })
}
}
}