0

我正在尝试将 DateTime 与 TextBoxFor 一起使用来显示 n 被编辑〜但我的模型的日期时间格式之一总是无法控制〜

看法

@Html.TextBoxFor(model => model.ClassDate,"{0:yyyy-MM-dd}", new {  @readonly = "true",style = "width:135px",type="date"})
@Html.TextBoxFor(model => model.ClassDate,"{0:yyyy-MM-dd}", new {  @readonly = "true",style = "width:135px"})
@Html.TextBoxFor(model => model.TeacherInfo.BDay,"{0:yyyy-MM-dd}", new {  @readonly = "true",style = "width:135px",type="date"})
@Html.TextBoxFor(model => model.TeacherInfo.BDay,"{0:yyyy-MM-dd}", new {  @readonly = "true",style = "width:135px"})

模型(我有两个表 n 使用外键)

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> BDay { get; set; }

[DataType(DataType.DateTime)]
[DisplayFormat(DataFormatString = "{0:MM-dd-yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> ClassDate { get; set; }

结果 https://docs.google.com/file/d/0B53j6yH_R3ZeTjc2SmMxYS1OUkk/edit?usp=sharing

4

1 回答 1

1

你有没有试过这样的方式,

@Html.TextBoxFor( model=>model.ClassDate, new { @readonly = "true", style = "width:135px", type="date", @Value = Model.ClassDate.Day + "/" + Model.ClassDate.Month + " / " + Model.ClassDate.Year})

我有同样的问题,但这真的对我有用....

于 2013-07-16T14:41:25.427 回答