Compare Dates DataAnnotations Validation asp.net mvc

前端 未结 5 1542
半阙折子戏
半阙折子戏 2020-12-15 13:11

Lets say I have a StartDate and an EndDate and I wnt to check if the EndDate is not more then 3 months apart from the Start Date

public class DateCompare : V         


        
5条回答
  •  庸人自扰
    2020-12-15 14:01

    Thanks for the info. I was left scratching my head when I wanted to bind the validation message to a property. If you switch the line

    [AttributeUsage(AttributeTargets.Class)]
    

    to...

    [AttributeUsage(AttributeTargets.Property)]
    

    you can move the compare above a specific property. Thanks for the info! Much help since my client is still running on 3.5 sp1. sad face

提交回复
热议问题