我正在使用像下面这样的 Object.cshtml,出于某种原因,public int MyInt { get;set; }
即使它们缺少必需的属性,也需要像这样的普通 int 属性,怎么会?我的编辑器模板中是否缺少某些内容?
@foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !ViewData.TemplateInfo.Visited(pm))) {
if (prop.HideSurroundingHtml) {
<text>@Html.Editor(prop.PropertyName)</text>
} else {
<div>
<div class="editor-label">
@if(prop.IsRequired) {
@Html.LabelFor(m => prop, @<em>(mandatory)</em>, prop.GetDisplayName())
} else {
@Html.Label(prop.PropertyName)
}
</div>
<div class="editor-field">
@Html.Editor(prop.PropertyName)
</div>
</div>
}
}