0
나는이처럼 하나 개의 필드는 디폴트 값을 갖는 형태를 만들
:ASP.NET MVC DataAnnotation - NullTextFormat
public class ApplicationDriverLicenseVM
{
[Required]
[Display(Name = "CDL Expiration Date")]
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "MM/DD/YYYY")]
public DateTime? CDLExpDate { get; set; }
: 내보기 모델 클래스를 생성
(비계에 의해)
그리고보기 :
<div class="form-group">
@Html.LabelFor(model => model.CDLExpDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CDLExpDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CDLExpDate, "", new { @class = "text-danger" })
</div>
</div>
하지만 결과에는 기본 텍스트 없습니다 그는 재 :
왜 그렇게 내가 잘못 무엇?
을 :
당신은 HTML 요소의
placeholder
속성을 사용하고EditorFor
의htmlAttributes
객체에 추가 할 수 있습니다. 자리 표시 자 = "MM/DD/YYYY"} – Nkosi'NullDisplayText'는'@Html.DisplayFor()'를 사용할 때만 존중됩니다.'new {htmlAttributes = new {@class = "form-control" –