我正在使用如下循环为视图模型上的每个属性呈现标签和编辑器:
@{
var properties = ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.IsComplexType && !ViewData.TemplateInfo.Visited(pm));
}
@foreach (var prop in properties)
{
<li>
<div class="form-line">
@{
if (prop.HideSurroundingHtml)
{
@Html.Editor(prop.DisplayName ?? prop.PropertyName)
}
else
{
@Html.Label((prop.IsRequired ? "* " : "") + (prop.DisplayName ?? prop.PropertyName))
@Html.Editor(prop.PropertyName)
}
}
</div>
</li>
}
和模型:
[Required]
[Display(Name = "Status")]
[UIHint("DropDown", "MVC", "SelectListName", "StatusSelectList")]
public Guid StatusId { get; set; }
[Required]
[Display(Name = "Emp Number")]
public string RefNum { get; set; }
[Required]
public string Surname { get; set; }
当我使用“Emp. No.”的显示名称时,根本不会呈现标签。当我使用“Emp. Number”的显示名称时,只会呈现“Number”标签。只有当我使用“Emp Number”的显示名称且没有任何句号时,我的完整预期标签才会呈现。这里发生了什么?