我想检查表单中的Datetime字段.该字段在01/10/2008和01/12/2008之间有效.以下是我定义viewmodel属性的方法:
[Required(ErrorMessage = "The date value is mandatory")]
[DataType(DataType.DateTime)]
[Range(typeof(DateTime), "01/10/2008", "01/12/2008")]
[DisplayName("When the work starts")]
public DateTime StartWork { get; set; }
Run Code Online (Sandbox Code Playgroud)
我想在客户端验证这一点.但我总是犯错误.我给出了值01/11/2008并告诉我,日期必须在01/10/2008和01/12/2008之间定义.我读到它没有jquery的客户端验证工作,不是吗?或者我忘了什么?有什么替代方案可以解决这个问题.
我想验证日期时间,我的代码是:
[Range(typeof(DateTime),
DateTime.Now.AddYears(-65).ToShortDateString(),
DateTime.Now.AddYears(-18).ToShortDateString(),
ErrorMessage = "Value for {0} must be between {1} and {2}")]
public DateTime Birthday { get; set; }
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type
Run Code Online (Sandbox Code Playgroud)
请帮我?