Validation 如何注释身份用户';s的电子邮件属性?
如果我有一个扩展了Validation 如何注释身份用户';s的电子邮件属性?,validation,asp.net-core,asp.net-identity,Validation,Asp.net Core,Asp.net Identity,如果我有一个扩展了IdentityUser的Customer模型,那么我可以轻松地为添加的属性添加注释 public class Customer : IdentityUser { [Required] public string Mobile { get; set; } // Other properties omitted for clarity } 如果我有一个,使客户能够更新他们的详细信息,我就不必对他们的手机号码进行任何验证(简单地假设在本例中,任何非空字符串都可以),因
IdentityUser
的Customer
模型,那么我可以轻松地为添加的属性添加注释
public class Customer : IdentityUser {
[Required]
public string Mobile { get; set; }
// Other properties omitted for clarity
}
如果我有一个
,使客户能够更新他们的详细信息,我就不必对他们的手机号码进行任何验证(简单地假设在本例中,任何非空字符串都可以),因为框架会为我这样做
如果我想注释任何身份属性,例如电子邮件
,我该怎么做?这些属性不会出现在myCustomer
类中,因为它们来自基本的IdentityUser
类
有人能帮忙吗?谢谢
如果我想对任何身份属性(如电子邮件)进行注释,我该怎么做?这些属性不会出现在my Customer类中,因为它们来自基本IdentityUser类
您可以覆盖和使用这些属性上的数据注释,如下所示
public class Customer : IdentityUser
{
[Required]
public string Mobile { get; set; }
[StringLength(20)]
public override string Email { get; set; }
// Other properties omitted for clarity
}
此外,您可以使用fluentapi来配置模型和覆盖数据注释。有关更多信息,请查看此文档:谢谢,这正是我需要的!