【发布时间】:2016-11-04 02:07:57
【问题描述】:
我有一个小问题,这是我的代码:
public partial class Tourist
{
public Tourist()
{
Reserve = new HashSet<Reserve>();
}
public int touristID { get; set; }
[Required]
[StringLength(50)]
public string touristNAME { get; set; }
public DateTime touristBIRTHDAY { get; set; }
[Required]
[StringLength(50)]
public string touristEMAIL { get; set; }
public int touristPHONE { get; set; }
public virtual ICollection<Reserve> Reserve { get; set; }
}
}
如何将 TouristBIRTHDAY 限制为 +18 岁?我想我必须使用这个功能,但我不知道放在哪里: 注意:这个函数是一个例子。
DateTime bday = DateTime.Parse(dob_main.Text);
DateTime today = DateTime.Today;
int age = today.Year - bday.Year;
if(age < 18)
{
MessageBox.Show("Invalid Birth Day");
}
谢谢 ;)
更新: 我遵循 Berkay Yaylaci 的解决方案,但我得到了 NullReferenceException。看来我的value参数是默认的,然后我的方法没有发布,为什么?解决办法是什么?
【问题讨论】:
标签: asp.net-mvc datetime required