2017-09-26 3 views
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; } 
: 내보기 모델 클래스를 생성

enter image description here

(비계에 의해)

그리고보기 :

<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> 

하지만 결과에는 기본 텍스트 없습니다 그는 재 :

enter image description here

왜 그렇게 내가 잘못 무엇?

+2

을 :

당신은 HTML 요소의 placeholder 속성을 사용하고 EditorForhtmlAttributes 객체에 추가 할 수 있습니다. 자리 표시 자 = "MM/DD/YYYY"} – Nkosi

+1

'NullDisplayText'는'@Html.DisplayFor()'를 사용할 때만 존중됩니다.'new {htmlAttributes = new {@class = "form-control" –

답변

1

NullDisplayTextHtml.EditorFor이 아닌 Html.DisplayFor에만 표시됩니다. 난 당신이 장소 홀더를 찾고있을 수 있습니다 생각

@Html.EditorFor(model => model.CDLExpDate, new { 
     htmlAttributes = new { 
      @class = "form-control", 
      @placeholder = "MM/DD/YYYY" 
     } 
}) 
관련 문제