namespace WebPORTAL.Models
{
public class Users
{
[Key]
public string FirstName { get; set; }
[Display(Name = "FIRST NAME")]
public string LastName { get; set; }
[Display(Name = "LAST NAME")]
public int Age { get; set; }
[Display(Name = "DATE OF BIRTH")]
public string Address { get; set; }
[Display(Name = "ADDRESS")]
public int MobileNumber { get; set; }
[Display(Name = "CELLPHONE NUMBER")]
public string Email { get; set; }
[Display(Name = "EMAIL ADDRESS")]
[Required(ErrorMessage = "PLEASE ENTER VALID EMAIL ADDRESS")]
public string Username { get; set; }
[Display(Name = "USERNAME")]
[Required(ErrorMessage = "PLEASE ENTER YOUR USERNAME")]
public string Password { get; set; }
[Display(Name = "PASSWORD")]
[DataType(DataType.Password)]
[Required(ErrorMessage = "PLEASE ENTER YOUR PASSWORD")]
}
}
我没有看到代码有什么问题。
答案 0 :(得分:1)
您已将属性放在属性后的某些属性上。他们应该在之前直接它所涉及的属性。
'问题'现在是最后一个没有关联属性的属性。这就是它失败的原因。
答案 1 :(得分:1)
您应该使用属性顶部的属性,而不是属性
你可以尝试:
[Key]
[Display(Name = "FIRST NAME")]
public string FirstName { get; set; }
[Display(Name = "LAST NAME")]
public string LastName { get; set; }
[Display(Name = "DATE OF BIRTH")]
public int Age { get; set; }
[Display(Name = "ADDRESS")]
public string Address { get; set; }
[Display(Name = "CELLPHONE NUMBER")]
public int MobileNumber { get; set; }
[Display(Name = "EMAIL ADDRESS")]
[Required(ErrorMessage = "PLEASE ENTER VALID EMAIL ADDRESS")]
public string Email { get; set; }
[Display(Name = "USERNAME")]
[Required(ErrorMessage = "PLEASE ENTER YOUR USERNAME")]
public string Username { get; set; }
[Display(Name = "PASSWORD")]
[DataType(DataType.Password)]
[Required(ErrorMessage = "PLEASE ENTER YOUR PASSWORD")]
public string Password { get; set; }