locked
Error In Add Record RRS feed

  • Question

  • User338455301 posted

    Hi,
    When I Add Record In Asp.net Core Mvc , the record is added but after that it's show this error.
    what's problem?

    City

     public City()
            {
    
            }
            [Key]
            public int City_ID { get; set; }
            [DisplayName("نام شهر")]
            [Required(ErrorMessage = "لطفا {0} را وارد نمایید")]
            [MaxLength(50)]
            public string CityName { get; set; }
            [DisplayName("کد شهر")]
            [Column(TypeName = "varchar(10)")]
            public string CityCode { get; set; }
            [DisplayName("وضعیت")]
            public bool IsActive { get; set; }
            [DisplayName("استان")]
            public virtual State State { get; set; }
            [DisplayName("استان")]
    
            public int State_ID { get; set; }
    
            public virtual IEnumerable<CustomerAddress> CustomerAddresses { get; set; }

    State

       [Key]
            public int State_ID { get; set; }
            [DisplayName("نام استان")]
            [Required(ErrorMessage = "لطفا {0} را وارد نمایید")]
            [MaxLength(50)]
            public string StateName { get; set; }
            [DisplayName("کد استان")]
            [Column(TypeName = "varchar(10)")]
            public string StateCode { get; set; }
            [DisplayName("وضعیت")]
            public bool IsActive { get; set; }
            [DisplayName("کشور")]
            [ForeignKey("Country")]
            public int CountryId { get; set; }
    
            public virtual Country Country { get; set; }
            public virtual List<City> Cities { get; set; }
            public virtual IEnumerable<CustomerAddress> CustomerAddresses { get; set; }




    Wednesday, January 16, 2019 7:40 AM

All replies

  • User753101303 posted

    Hi,

    It means you try to add a City with a State_ID value that doesn't match a primary key value found in the State_tb column.

    In plain English, you try to add  a city which doesn't belong to an existing state.

    Wednesday, January 16, 2019 4:17 PM