我在ASP中使用引导程序日期选择器。NET MVC应用程序。当我试图发布表单时,我收到一个错误,说"The field Start Date must be a date."
我正在使用"jquery.validate.js"
在客户端进行验证。我的日期选择器格式,我已自定义为"dd-MM-yyyy"
(例如:2016年5月12日)。
此错误仅发生在IE中,在Chrome浏览器中运行良好。
通过谷歌搜索,我尝试了不同的方法:
1) 在模型中设置数据注释
[Required]
[Display(Name = "Start Date")]
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)]
2)jquery.validate.js
中编辑的date
函数
date: function (value, element) {
return value.match("^d{2}-[a-zA-Z]{3}-d{4}$");
},
但似乎什么都不起作用。大多数问题都是围绕JQuery日期选择器讨论的,但我的问题是引导程序日期选择器。
如有任何帮助,我们将不胜感激。
有一些修复:
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime BirthDate { get; set; }
2。走向全球asax并添加:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
CultureInfo newCulture = (CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
newCulture.DateTimeFormat.ShortDatePattern = "dd/MMM/yyyy";
newCulture.DateTimeFormat.DateSeparator = "/";
Thread.CurrentThread.CurrentCulture = newCulture;
}
最后在您的View 中尝试
@Html。TextBoxFor(model=>model.BirthDate,"{0:dd/MM/yyyy}",new{@class="日期选择器表单控件"})