C# 是否可以使用DataAnnotation让用户以精确的日期格式输入日期?
我在一个表单上有一个日期选择器,我想让用户输入带有世纪的日期,并且不允许在没有世纪的情况下插入日期C# 是否可以使用DataAnnotation让用户以精确的日期格式输入日期?,c#,spring-mvc,C#,Spring Mvc,我在一个表单上有一个日期选择器,我想让用户输入带有世纪的日期,并且不允许在没有世纪的情况下插入日期 [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")] [Display(Name = "Birthdate")] [Required] public DateTime? Birthdate { get; set; } 但是,这仍然允许用户输入1/1/91。使用ApplyFormatInEditMode: [Dis
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}")]
[Display(Name = "Birthdate")]
[Required]
public DateTime? Birthdate { get; set; }
但是,这仍然允许用户输入1/1/91。使用ApplyFormatInEditMode:
[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:MM/dd/yyyy}")]
使用ApplyFormatInEditMode:
[DisplayFormat(ApplyFormatInEditMode=true, DataFormatString = "{0:MM/dd/yyyy}")]
您需要一个客户端脚本。我用这个:我想用模型验证来完成它…你需要一个客户端脚本。我用这个:我想用模型验证来完成它。。。