Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Validation 如何注释身份用户';s的电子邮件属性?_Validation_Asp.net Core_Asp.net Identity - Fatal编程技术网

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
}
如果我有一个
,使客户能够更新他们的详细信息,我就不必对他们的手机号码进行任何验证(简单地假设在本例中,任何非空字符串都可以),因为框架会为我这样做

如果我想注释任何身份属性,例如
电子邮件
,我该怎么做?这些属性不会出现在my
Customer
类中,因为它们来自基本的
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来配置模型和覆盖数据注释。有关更多信息,请查看此文档:

谢谢,这正是我需要的!