EditorFor type = date,只显示掩码

时间:2018-03-19 16:27:13

标签: c# asp.net-mvc data-annotations html-helper

我有一个模型类:

public class mOrderSnapshot
{
[Display(Name = "Birthday")]
[Required(ErrorMessage = "*")]
[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
public DateTime Birthday { get; set; }

我尝试在输入中插入日期。

@Html.EditorFor(model => model.Birthday, new { @class = "usercontrol"})

但我只看到面具дд.мм.гггг 为什么我不能插入值(日期)。

2 个答案:

答案 0 :(得分:0)

@Html.TextBoxFor(model => model.Birthday, new { @class = "usercontrol", @type="date"})

或:

@Html.EditorFor(model => model.Birthday, new {@class = "usercontrol", @type="date"})

答案 1 :(得分:0)

我必须使用这个: [DisplayFormat(ApplyFormatInEditMode = true,DataFormatString =“{0:yyyy-MM-dd}”)]

DataFormatString =“{0:yyyy-MM-dd}

相关问题