如何使用Html.TextBoxFor与输入类型=日期
1个回答
展开全部
Try this;
@Html.TextBoxFor(model => model.CreationDate,
new { @type = "date", @Value = Model.CreationDate.ToString("yyyy-MM-dd") })
You have to handle null when setting the value.
OR
If you can change the Model you can try this;
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime CreationDate{ get; set; }
and in your view you can use EditorFor helper.
@Html.EditorFor(model => model.CreationDate, new { @type = "date" })
@Html.TextBoxFor(model => model.CreationDate,
new { @type = "date", @Value = Model.CreationDate.ToString("yyyy-MM-dd") })
You have to handle null when setting the value.
OR
If you can change the Model you can try this;
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime CreationDate{ get; set; }
and in your view you can use EditorFor helper.
@Html.EditorFor(model => model.CreationDate, new { @type = "date" })
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询