ASP.NET 4.3 Forests: add a controller and add a view - another behavior?

I am trying to dig in ASP.NET MVC 3 using standard tutorials on the Internet, and I am facing the fear problem.

I am currently following the samples in the book using the Cinema class with movie genres stored in a separate object associated with a foreign key (ok, I'm from Germany, so my class is named in German). Here I show only the relevant properties. This is the first database approach using DbContext, my model was created from edmx using the EF 4.x DbContext Generator, and edmx was automatically created from the database.

public partial class Film { public Film() { } public int ID { get; set; } public string Titel { get; set; } public int GenreID { get; set; } public virtual Genre Genre { get; set; } } public partial class Genre { public Genre() { } public int GenreID { get; set; } public string Name { get; set; } } 

When I create a new controller with a CRUD view for the Film class using the DBContext that the DBSet provides, I get an Edit view that uses the DropdownList to edit the GenreID labeled Genre. Good. This is what I want.

But then, I tried to create another edit, separately. Therefore, I right-clicked on my action editing method, selected “Add View”, named it “Edit2”, used the movie as a model and “Edit” as a forest template. In this view, I got a simple "EditorFor (m-> m.GenreID)" tagged as GenreID. This is not what I want.

Of course, I can change this manually. Of course, I can download many tools for forests that claim to be better.

But I want to understand if this is an error in EF templates, or if my model is not built correctly, so Genre / GenreID gets confused. When I create everything at once, scaffolding creates DropDown, so there should be “just” some details that are missing.

+4
source share
1 answer

You will need to call your action in your controller "Edit2".

0
source

All Articles