Hi,
I have an Employee Class in which you have to capture the employee's physical and postal address.
Both the physical and postal address require a Province.
I have created a Province Class to store the Provinces.
I need to have a dropdown list of the Provinces for both the physical and postal address of a single employee but when I add the second dropdown list, it doesn't work.
My Employee Class is as follows;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.ComponentModel.DataAnnotations.Schema;
- using System.Linq;
- using System.Web;
- namespace LMKSystem.Models
- {
- public class Employee
- {
- [Key]
- public int EmployeeId { get; set; }
- [Display(Name = "Employee Number")]
- [MaxLength(50)]
- public string EmployeeNumber { get; set; }
- //Foreign Key from Title Class
- [Display(Name = "Title")]
- public int TitleId { get; set; }
- [ForeignKey("TitleId")]
- public virtual Title Titles { get; set; }
- //end
- [MaxLength(50)]
- //[Required(ErrorMessage ="An employee name is needed to continue")]
- public string Name { get; set; }
- [Display(Name = "Second Name")]
- [MaxLength(50)]
- public string SecondName { get; set; }
- [MaxLength(50)]
- public string Surname { get; set; }
- [Display(Name = "A.K.A")]
- [MaxLength(50)]
- public string AKA { get; set; }
- [Display(Name = "ID Number")]
- [MaxLength(50)]
- public string IdNumber { get; set; }
- [Display(Name = "Date of Birth")]
- //[DataType(DataType.Date)]
- [DisplayFormat(DataFormatString = "{dd/mm/yyyy}", ApplyFormatInEditMode = true)]
- public DateTime? DOB { get; set; }
- //Foreign Key from Gender Class
- [Display(Name = "Gender")]
- public int GenderId { get; set; }
- [ForeignKey("GenderId")]
- public virtual Gender Genders { get; set; }
- //end
- //Foreign Key from Group
- [Display(Name = "Group")]
- public int GroupId { get; set; }
- [ForeignKey("GroupId")]
- public virtual Group Groups { get; set; }
- //end
- //Foreign Key from Work Permit
- [Display(Name = "Work Permit")]
- public int WorkPermitId { get; set; }
- [ForeignKey("WorkPermitId")]
- public virtual WorkPermit WorkPermits { get; set; }
- //end
- [Display(Name = "Expiry Date")]
- public DateTime? WorkPermitExpireDate { get; set; }
- //Foreign Key from Passports
- [Display(Name = "Passport")]
- public int PassportId { get; set; }
- [ForeignKey("PassportId")]
- public virtual Passport Passports { get; set; }
- //end
- [Display(Name = "Expiry Date")]
- public DateTime? PassportExpiryDate { get; set; }
- //ForeignKey from Language
- [Display(Name = "Language")]
- public int LanguageId { get; set; }
- [ForeignKey("LanguageId")]
- public virtual Language Languages { get; set; }
- //end
- //ForeignKey from Marital Status
- [Display(Name = "Marital Status")]
- public int MaritalStatusId { get; set; }
- [ForeignKey("MaritalStatusId")]
- public virtual Marital Maritals { get; set; }
- //end
- [Display(Name = "Mobile")]
- public string EmployeeMobileNo { get; set; }
- [Display(Name = "Home")]
- public string EmployeeHomeNo { get; set; }
- [Display(Name = "Name & Surname")]
- public string EmergencyName { get; set; }
- [Display(Name = "Work")]
- public string EmergencyWorkNo { get; set; }
- [Display(Name = "Mobile")]
- public string EmergencyMobileNo { get; set; }
- [Display(Name = "Email")]
- [DataType(DataType.EmailAddress)]
- [RegularExpression(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", ErrorMessage = "Email is not valid. Insert a correct email address.")]
- public string EmergencyEmail { get; set; }
- [Display(Name = "Postal Address")]
- public string PostalAddress { get; set; }
- [Display(Name = "City/Town")]
- public string PostalCityTown { get; set; }
- [Display(Name = "Postal Code")]
- public string PostalCode { get; set; }
- //ForeignKey from Province
- [Display(Name = "Province")]
- public int ProvinceId { get; set; }
- [ForeignKey("ProvinceId")]
- public virtual Province Provinces { get; set; }
- //end
- [Display(Name = "Physical Address")]
- public string PhysicalAddress { get; set; }
- [Display(Name = "City/Town")]
- public string PhysicalTownCity { get; set; }
- [Display(Name = "Postal Code")]
- public string PhysicalPostalCode { get; set; }
- //ForeignKey from Province
- [Display(Name = "Province")]
- public int ProvinceId { get; set; }
- [ForeignKey("ProvinceId")]
- public virtual Province Provinces { get; set; }
- //end
- }
- }
My Province Class is;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Web;
- namespace LMKSystem.Models
- {
- public class Province
- {
- [Key]
- public int ProvinceId { get; set; }
- [Display(Name = "Province")]
- public string SAProvince { get; set; }
- }
- }
My DbSet is as follows;
- public class ApplicationDbContext : IdentityDbContext
- {
- public DbSet
Employees { get; set; } - public DbSet
Titles { get; set; } - public DbSet
Genders { get; set; } - public DbSet
Groups { get; set; } - public DbSet
WorkPermits { get; set; } - public DbSet
Passports { get; set; } - public DbSet
Languages { get; set; } - public DbSet
Maritals { get; set; } - public DbSet
Provinces { get; set; } - }
How can I have one dropdown list for the postal address Province and one dropdown list for the physical address Province in the same class?
I am fairly new to dropdown lists.
Thanking you in advance.
Regards,
Kyle
Avnish KumarPosted Feb 17, 2020, 10:20 AM