1

私は以下のような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>
    }
}
4

1 に答える 1

2

不要なフィールドをnull許容に変更してみてください。

public int? MyInt { get;set; }
public DateTime? MyDateTime { get;set; }
public bool? MyBool { get;set; }
于 2013-01-07T18:49:27.873 に答える