를 작동하지 않는 내 모델 클래스에 dataannotation을 다음 있습니다 :DisplayFormat Dataannotation
<tr>
<td>@Html.LabelFor(x => x.DateOfBirth, new { @class = "lbl" }, "Date Of Birth") </td>
<td>@Html.TextBoxFor(x => x.DateOfBirth, new { @class = "w100 _dob" })
<br>@Html.ValidationMessageFor(x => x.DateOfBirth)
</td>
</tr>
당신이 제안시겠습니까 : 내보기에 다음 사용하면
[Required(ErrorMessage = "Required")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime DateOfBirth { get; set; }
을하고, 나는 유효성 검사 오류가 얻을 해달라고 해결책 ?
내가 눈치 챘 :
그리고 방법에 의해 DisplayFormat 속성이 Html.EditorFor 도우미와 함께 사용되며, 당신이 사용하고있는 것입니다되는 Html.TextBoxFor 도우미와 엄격하게 적용되지 않습니다
작업중인 프로젝트의 EF POCO 중 하나에 대해'Html.TextBoxFor'를 사용하면'DisplayFormat'이 올바르게 작동합니다. 그러나 편집중인 ViewModel에서이 필드의 동일한 복사본에 똑같은'DisplayFormat'을 사용하려고하면,이 필드는 기본 디스플레이 포맷을 사용합니다. 그러나 고유 한 'DisplayName'이 수행합니다.이 'DataAnnotations'집합을 사용한다는 것을 알 수 있습니다. 즉, 'DisplayName'에 'VMTest'를 추가했습니다. 이것은 내 프로젝트에서 특정한 무엇인가의 결과 일 수 있지만, 그것은 나에게 약간의 혼란을 일으키는 흥미로운 특질이었다. –