1

我希望属性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; }
}

我已经尝试一起删除该属性,但它仍然根据需要对其进行分类。

我哪里错了?

4

1 回答 1

6

你应该让它可以为空

public DateTime? DateOfBirth { get; set; }
于 2013-03-15T12:06:42.720 回答