我希望将属性 DateOfBirth 作为模型绑定器的可选项
public class RegisterModel
{
[Required]
public int MP_CustomerID { get; set; }
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
[Required]
[DataType(DataType.Password)]
[Compare("Password")]
public string PasswordConfirm { get; set; }
[Required(AllowEmptyStrings = true, ErrorMessage="This is the error message")]
public DateTime DateOfBirth { get; set; }
public int NoOfVehicles { get; set; }
}
我尝试将所有属性一起删除,但它仍然按需要对其进行分类。
我哪里错了?
答案 0 :(得分:6)
你应该让它可以为空
public DateTime? DateOfBirth { get; set; }