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; }
和View(腳手架):
<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>
,但結果沒有默認的文本,他再次:
爲什麼這麼和我做什麼錯誤?
我相信你可能會尋找一個佔位符。 'new {htmlAttributes = new {@class =「form-control」,placeholder =「MM/DD/YYYY」}' – Nkosi
'NullDisplayText'只有在使用'@ Html.DisplayFor() –