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 8768949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:12:07+00:00 2026-06-13T17:12:07+00:00

Using MVC4 and EF5 codefirst. Got a problem whereby when creating a new data

  • 0

Using MVC4 and EF5 codefirst. Got a problem whereby when creating a new data record with reference to a row with a foreign key. Listing created entries everything looks fine:

@foreach (var item in Model) {
   @Html.DisplayFor(modelItem => item.Location.name)
   @Html.DisplayFor(modelItem => item.Action.name)
   ...

Creating a new record the reference fails to display the foreign content (names):

    ...
    @Html.LabelFor(model => model.locationID)
    @Html.DisplayFor(model => model.Location.name)

    @Html.LabelFor(model => model.actionID)
    @Html.DisplayFor(model => model.Action.name)
    ...

The foreign keys are correctly filled in the controller (see simplied example)

    public ActionResult Create()
    {
        Timerecord tm = new Timerecord();

        tm.currentTime = DateTime.Now;
        tm.locationID = 1;
        tm.actionID = 5;

        ViewData.Model = tm;
        return View();
    }

and the record is correctly created in the database. Just the names are not displayed on the view. Do I have to fetch the associated reocrd myselfs during the Create?

  • 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-13T17:12:09+00:00Added an answer on June 13, 2026 at 5:12 pm

    I don’t see any calls to SaveChanges() in your code. You need to invoke this in order for the foreign key properties to load the navigation properties. Either that or, like you said at the end of your question, load them explicitly.

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

Sidebar

Related Questions

I am using MVC4 and EF5 codefirst. I have a problem whereby when creating
I am using EF5 codefirst in an ASP.NET MVC4 app. I have products and
I am creating an asp.net mvc4 site using entity framework 5 with codefirst and
I am creating a web api using asp.net mvc4 and the response output is
I am new to asp.net MVC, using MVC4 at the moment, learning by tutorials
I'm working on a new asp.net mvc4 project using Visual Studio 2011 beta and
I just upgraded my MVC4 project to .NET 4.5 and EF5 and started using
I'm building an MVC4 app using EF5 and ninject. Something broke when I upgraded
I am starting a new project using MVC4 and would like to use dependency
Problem: I'm using MVC4 WebAPI and am throwing an error during a Get() call.

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.