'... DataType'不包含'Email'的定义

时间:2021-12-25 16:56:58

I'm using Identity, and the IdentityUsers properties are the next: https://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.entityframework.identityuser_properties%28v=vs.108%29.aspx Well, the problem is I have in the AspNetUsers table "Email" and "PasswordHash", but appears the error'System.ComponentModel.DataAnnotations.DataType' does not contain a definition for 'Email' and 'PasswordHash') if I put "Datatype.Email" instead of "DataType.EmailAddress" and "DataType.PasswordHash" instead of "DataTtype.Password".

我正在使用Identity,而IdentityUsers属性是下一个:https://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.entityframework.identityuser_properties%28v=vs.108%29.aspx Well ,问题是我在AspNetUsers表“Email”和“PasswordHash”中,但如果我输入“数据类型”,则出现错误'System.ComponentModel.DataAnnotations.DataType'不包含'Email'和'PasswordHash'的定义.Email“而不是”DataType.EmailAddress“和”DataType.PasswordHash“而不是”DataTtype.Password“。

public class RegisterViewModel
{
    [Required]
    [DataType(DataType.Email)]
    [Display(Name = "Email")]
    public string Email { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The password must have at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.PasswordHash)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.PasswordHash)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "Different passwords.")]
    public string ConfirmPassword { get; set; }
}

1 个解决方案

#1


The error is telling you exactly what you need. DataType is an enumeration which only allows specific values. These in turn are used for validation in the MVC world to ensure that you have a valid EmailAddress in the field, whatever it happens to be called.

错误告诉您确切的需要。 DataType是一个只允许特定值的枚举。这些反过来用于MVC世界中的验证,以确保您在该字段中具有有效的EmailAddress,无论它恰好被调用。

[DataType(DataType.Email)] // Not Valid
[DataType(DataType.EmailAddress)] // Valid
[DataType(DataType.PasswordHash)] // Not Valid
[DataType(DataType.Password)] // Valid

For the full list of valid values, see Intellisense or this URL: https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatype%28v=vs.110%29.aspx

有关有效值的完整列表,请参阅Intellisense或此URL:https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatype%28v=vs.110%29.aspx

#1


The error is telling you exactly what you need. DataType is an enumeration which only allows specific values. These in turn are used for validation in the MVC world to ensure that you have a valid EmailAddress in the field, whatever it happens to be called.

错误告诉您确切的需要。 DataType是一个只允许特定值的枚举。这些反过来用于MVC世界中的验证,以确保您在该字段中具有有效的EmailAddress,无论它恰好被调用。

[DataType(DataType.Email)] // Not Valid
[DataType(DataType.EmailAddress)] // Valid
[DataType(DataType.PasswordHash)] // Not Valid
[DataType(DataType.Password)] // Valid

For the full list of valid values, see Intellisense or this URL: https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatype%28v=vs.110%29.aspx

有关有效值的完整列表,请参阅Intellisense或此URL:https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.datatype%28v=vs.110%29.aspx