简体   繁体   中英

Invalid token '}' in class, struct, or interface member declaration

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")]

    } 
}

I don't see what's wrong with the code.

You have put your attributes on some properties after the property. They should come directly before the property it concerns.

The 'problem' now is the last attribute which doesn't have an associated property. That is why it is failing.

You should use Attributes top of your property, not below of property,

you can try that:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM