Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:45:02+00:00 2026-06-12T09:45:02+00:00

This is driving me crazy, and I have studied the related posts on StackOverflow.

  • 0

This is driving me crazy, and I have studied the related posts on StackOverflow.

Basically I have 2 tables, Album and Genre with the former having a foreign key to Genre. I have modelled this using Model First in EF5, and generated the context and class files using MS’s T4 generator. Thus my Domains Class code is:

{
using System;
using System.Collections.Generic;

public partial class Album
{
    public int Id { get; set; }
    public string Title { get; set; }
    public decimal Price { get; set; }
    public string AlbumArtUrl { get; set; }

    public int GenreId {get; set;}
    public virtual Genre Genre { get; set; }
}
}

You will notice that I have added :

public int GenreId {get; set;}

as per guidance inorder to enable the scaffolding to create the dropdowns in the Views and “SelectList” code in the controller. But it does not! However it does create, in the view:

     <div class="editor-label">
        @Html.LabelFor(model => model.GenreId)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.GenreId)
        @Html.ValidationMessageFor(model => model.GenreId)
    </div>

So I am really puzzled. Any ideas would be greatly appreciated.

Thanks,

Ed

P.S. I am running VS2010 SP1 with ASP.NET MVC 3 Tools Update it seems, since I tried to install it and it said that it was already installed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:45:03+00:00Added an answer on June 12, 2026 at 9:45 am

    yee … aah!!! I have got it working with the MS Scaffold. Now I need to figure out how. I believe the issue was with the fact that I am using Model First and I need to ensure that I add the extra foreign key property into the model and not just into the Domain Class code, it needs to be in the EDMX. However this creates another problem in that 2 fields are now creates in SQL Server, one from the Navigation property and the other from this field. I may need to play with the mapping. I will

    Controller code generated:

        // GET: /Album/Create
    
        public ActionResult Create()
        {
            ViewBag.GenreId = new SelectList(db.Genre, "Id", "Name");
            return View();
        } 
    

    Associated View Code:

        <div class="editor-label">
            @Html.LabelFor(model => model.GenreId, "Genre")
        </div>
        <div class="editor-field">
            @Html.DropDownList("GenreId", String.Empty)
            @Html.ValidationMessageFor(model => model.GenreId)
        </div>
    

    This is what I wanted. Obviously if anyone wishes to make comment on this then great, but it does work.

    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy. I have a PHP script that gets some data
This is driving me crazy. I have a very simple user control: public int?
This is driving me crazy and I can't find the answer anywhere. I have
Ok, this is driving me crazy. I have a CA that needs to know
This has been driving me crazy for the past few minutes I have a
This has been driving me crazy. I think I have everything in place but
Any regex gurus around here? its driving me crazy. Say I have this string:
This is driving me crazy: I have function void gst_init(int *argc, char **argv[]); in
This is driving me crazy! I have read at least 5 questions on here
Ok this is driving me crazy. I have a user account page. Where you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.