MVC Scaffolding not showing fields on view in EF Core 2.0

asp.net asp.net-core asp.net-mvc c# entity-framework-core

Accepted Answer

Okay, I'll answer my own question in the hopes that someone else will find the solution if they have the same problem as me.

It turned out that Entity Framework was confused about whether or not the relationship on my model was indeed one since I had not implemented it correctly.

So, to sum up, you must inform all classes that communicate with one another on how and by whom their field will be utilized.

Package.CS

public class Package
    {
        public int PackageId { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public int Price { get; set; }
        public int CategoryID { get; set; }


        [Required]
        public virtual Category Category { get; set; }
        public virtual ICollection<Product> Products { get; set; }

    }

Please take notice that you must also inform the model you want to use for your other class of the field's crucial information. Regarding me:

public int CategoryID { get; set; }

Category.CS

public class Category
    {
        public int CategoryId { get; set; }
        [Required]
        public string CategoryName { get; set; }

        public virtual ICollection<Package> Packages { get; set; }
    }

And for the most part, they are the only adjustments I had to make to my model.

If, for any reason, you just get the ID of your table to show on the SelectView, don't panic. Just means you forgot to mark as [Required] the text field. [you cannot allow nulls]

0
10/23/2017 7:45:28 PM






Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow