MVC에서 일부 DateTimes의 형식을 지정하려고하지만 DisplayFormat이 Nullable 개체에 적용되지 않아 그 이유를 파악할 수 없습니다. 그것은 CreatedDateTime에 완벽하게 잘 작동하지만 (나는 내가 한 희망) 당신의 의도가 올바른 이해하면되지 LastModifiedDateTime 아래 DisplayFormat이 Nullable과 호환되지 않습니다. <DateTime>
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yy hh:mm tt}")]
public DateTime CreatedDateTime { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yy hh:mm tt}")]
public Nullable<DateTime> LastModifiedDateTime { get; set; }
는보기
<div class="editor-field">
@Html.DisplayFor(model => model.CreatedDateTime)
<br />
@Html.Raw(TimeAgo.getStringTime(Model.CreatedDateTime))
</div>
@if (Model.LastModifiedDateTime.HasValue)
{
<div class="editor-label">
@Html.LabelFor(model => model.LastModifiedDateTime)
</div>
<div class="editor-field">
@Html.DisplayFor(model => model.LastModifiedDateTime)
<br />
@Html.Raw(TimeAgo.getStringTime(Model.LastModifiedDateTime.Value)) By: @Html.DisplayFor(model => model.LastModifiedBy)
</div>
}
'Nullable'대신 'DateTime?'을 사용하면 실패합니까? –
TyCobb
DateTime으로 변경 하시겠습니까? 아무 효과가 없다. – Preston
@TyCobb 'DateTime?'과 'Nullable'은 동일합니다. –