我使用的是引导3日期选择器(http://eonasdan.github.io/bootstrap-datetimepicker/)提出一个日期时间选择器的模型属性:引导3日期选择器和日期时间验证错误
型号:
[Table("Calls")]
public partial class Call
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required(ErrorMessage = "Campo obrigatório")]
[Display(Name = "Data e Hora de início")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd-MM-yyyy HH:mm}")]
public DateTime DateOfTheCall { get; set; }
}
查看:
<div class="form-group">
@Html.LabelFor(model => model.DateOfTheCall, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.DateOfTheCall, new { htmlAttributes = new { @class = "form-control date" } })
@Html.ValidationMessageFor(model => model.DateOfTheCall, "", new { @class = "text-danger" })
</div>
</div>
我设定的日期格式的日期选择器:
// initialise any date pickers
$('.date').datetimepicker({
locale: 'pt',
format: 'DD-MM-YYYY HH:mm'
});
我还设置了文化在web.config文件:
<globalization culture="pt-PT"/>
但我总是得到错误信息:
The field Data e Hora de início must be a date.
你可以通过javascript验证你的datetimepicker,创建一个函数来检查值。 –
我认为你的@ Html.EditorFor是以type ='textbox'的文本框生成的,但它应该是type ='date'。这可能可以帮助你 – Nimmi
@Nimmi嗨,我该如何改变EditorFor的类型? – Patrick