Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以使用DataAnnotation让用户以精确的日期格式输入日期?_C#_Spring Mvc - Fatal编程技术网

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}")]

您需要一个客户端脚本。我用这个:我想用模型验证来完成它…你需要一个客户端脚本。我用这个:我想用模型验证来完成它。。。