我的SchoolEvents
模型上有一个StartDate
和EndDate
,我想知道是否有任何数据注释我可以用来验证StartDate
是否小于或等于EndDate
并且EndDate
是否大于或等于StartDate
?
From my point of view, you have to build a custom validation attribute . You can look at the link to validate follow specific your validation. It will take your efforts so much. Instead of you use data annotation you should apply Fluent Validation which will help you reduce efforts. It is easy to setup, straight forward and separates of concern, you do not need mixing between view models, domain objects, and validations which depend on business rule.
You can achieve what you need by installing and using foolproof
nuget package.
Install foolproof
nuget package and use its extra useful attributes like the following:
public class EventViewModel
{
[Required]
public string Name { get; set; }
[Required]
public DateTime Start { get; set; }
[Required]
[GreaterThan("Start")]
public DateTime End { get; set; }
}
More examples of exactly what you need are here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.