I am trying to dig into ASP.NET MVC 3, using the standard tutorials in the web, and I encounter a strage problem.

Currently, I am following the samples in a book, using a "Movie" class with movie genres stored in a separate entity, connected with a foreign key (okay, I am from Germany, so my class is named in German). I show only the relevant properties here. It's a database first approach using DbContext, my model was created from the edmx by using the EF 4.x DbContext Generator and the edmx was automatically created from the data base.

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 CRUD Views for the Film class, using a DBContext that provides a DBSet, I get an Edit view that uses a DropdownList to edit GenreID, labelled "Genre". Fine. That's what I want.

But then, I tried to create another edit view, separately. So I right-clicked into my Edit Action-Method, selected "Add View", called it "Edit2", used Film as model and "Edit" as scaffold template. In this view, I got a simple "EditorFor(m->m.GenreID)", labelled GenreID. That's not what I want.

Of course, I can change that manually. Of course, I can download a slew of scaffolding tools that claim to do better.

But I want to understand if this is a bug in the EF templates, or if my model is built wrong so that Genre / GenreID gets confused. When I create everything at once, scaffolding creates a DropDown, so there must be "just" some detail that's missing.

share|improve this question
    
I'm having this same problem. I thought it was an issue with the T4 templates, but I think it has something to do with the data passed between the wizard and the T4 template (A.K.A. Host) – Brian Jun 21 '12 at 20:04
    
@Brian & Rolf, did you guys figure this out? I'm having similar issues. I copied the code templates locally to modify them and for some reason it doesn't seem to pick up any foreign key relations any more. – PostureOfLearning Sep 7 '13 at 3:55
    
I'm sorry, but I abandoned the topic a year ago. Other work became more important. – Rolf Dec 2 '13 at 17:05

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.