gpt4 book ai didi

c# - Model Binder - 如何使可选

转载 作者:太空宇宙 更新时间:2023-11-03 19:17:12 24 4
gpt4 key购买 nike

我希望使属性 DateOfBirth 相对于模型 Binder 可选

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; }
}

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

我哪里错了?

最佳答案

你应该让它可以为空

public DateTime? DateOfBirth { get; set; }

关于c# - Model Binder - 如何使可选,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15432022/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com