C# datepicker存在日期验证错误
我正在处理MVC和Jquery,我有一个表单为网站创建一个新事件。在日期部分,我使用datepicker显示日历,并让用户选择日期。我的格式是:C# datepicker存在日期验证错误,c#,jquery,asp.net-mvc,C#,Jquery,Asp.net Mvc,我正在处理MVC和Jquery,我有一个表单为网站创建一个新事件。在日期部分,我使用datepicker显示日历,并让用户选择日期。我的格式是: format: 'dd/mm/yyyy', 但是当我提交表单时,它总是失败,并告诉我无效的格式。我发现问题在于,当我选择日期2016年3月24日时,它将月份设置为24,日期为3(表示3月) 这里发生了什么事,有人能帮我吗?多谢各位 型号: public SeminarListViewModel() { Document
format: 'dd/mm/yyyy',
但是当我提交表单时,它总是失败,并告诉我无效的格式。我发现问题在于,当我选择日期2016年3月24日时,它将月份设置为24,日期为3(表示3月)
这里发生了什么事,有人能帮我吗?多谢各位
型号:
public SeminarListViewModel()
{
Documents = new List<DocumentDisplayViewModel>();
}
public string EventID {get;set;}
public string Name { get; set; }
public short Capacity { get; set; }
[DataType(DataType.Date)]
public DateTime StartDate { get; set; }
[DataType(DataType.Date)]
public DateTime EndDate { get; set; }
public List<DocumentDisplayViewModel> Documents { get; set; }
}
public-SeminarListViewModel()
{
文件=新列表();
}
公共字符串EventID{get;set;}
公共字符串名称{get;set;}
公共短容量{get;set;}
[数据类型(DataType.Date)]
公共日期时间起始日期{get;set;}
[数据类型(DataType.Date)]
公共日期时间结束日期{get;set;}
公共列表文档{get;set;}
}
在类中,在开始日期
和结束日期
属性的上方添加以下内容:
using System.ComponentModel.DataAnnotations; /*put above namespace*/
[Display(Name = "Start Date:")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public System.DateTime StartDate { get; set; }
[Display(Name = "End Date:")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public System.DateTime EndDate { get; set; }
问题是您的
开始日期
和结束日期
将日期作为格式“MM/dd/yyyy”,并且没有一个月是23或24。。。你能发布你的模型吗?嗨,谢谢你的回复,我发布我的代码。DataFormatString和ApplyFormatInEditMode适合我的代码?@kcc我看到你发布了你的代码,谢谢。他们应该。。您的模型中已经有数据注释,因此它们应该可以工作。。我将根据您发布的内容进行编辑,向您展示它的外观。如果我将您提供给{0:dd/MM/yyyy}@kcc的日期格式交换给您,这是您的首选,我尝试了,它不起作用。可能是我把代码放错地方了吗