Razor - INPUTタグで日付を編集する

Viewでフォーマットを指定する

 @Html.TextBoxFor(m => m.Date, "{0:dd/MM/yyyy}", new { @class = "width-xx" })

参考

http://stackoverflow.com/questions/17602594/mvc-4-editorfor-textboxfor-and-date-field

ViewModelでDisplayFormatアトリビュートを使う

ViewModel

 [Display(Name = "When was that document issued ?")]
 [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
 public DateTime? LiquorLicenceDocumentIssueDate { get; set; }

View

 @Html.EditorFor(m => m.LiquorLicenceDocumentIssueDate)

参考

http://stackoverflow.com/questions/4679352/converting-datetime-format-using-razor/8362126#8362126


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS