Razor Page SelectList not populating when using ViewModel #26228
Unanswered
kmichelle7601
asked this question in
Q&A
Replies: 1 comment 2 replies
-
Exactly, where is your foreign key in this code, without that you cannot get values return in your select list |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I feel like I'm doing exactly what the tutorial is saying in https://docs.microsoft.com/en-us/aspnet/core/data/ef-rp/update-related-data?view=aspnetcore-6.0 but my query to populate my select list is not returning any values. I am wondering if it's because I don't have foreign key relations on the database I inherited.
I see this in the Contuso sample but not sure if this is because the database is being created within the sample tutorial. Do I need this in my project too? Is this even related to my possible issue?
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity().ToTable(nameof(Course))
.HasMany(c => c.Instructors)
.WithMany(i => i.Courses);
modelBuilder.Entity().ToTable(nameof(Student));
modelBuilder.Entity().ToTable(nameof(Instructor));
}
Beta Was this translation helpful? Give feedback.
All reactions