title: Foreign Key Just showing a number which is associated with the primary key
body: <p>I want a way in which I can display the value of the Foreign key rather then displaying a number. For example I have the following view to show all reviews:</p>
  
  <pre><code>@model IEnumerable&lt;Games.Models.tblReview&gt;
  
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;h2&gt;Index&lt;/h2&gt;
  
  &lt;p&gt;
      @Html.ActionLink("Create New", "Create")
  &lt;/p&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;
              ReviewID
          &lt;/th&gt;
          &lt;th&gt;
              Recomendation
          &lt;/th&gt;
          &lt;th&gt;
              AvoidOrBuy
          &lt;/th&gt;
          &lt;th&gt;
              Score
          &lt;/th&gt;
          &lt;th&gt;
              GameIDFK
          &lt;/th&gt;
          &lt;th&gt;
              UserName
          &lt;/th&gt;
          &lt;th&gt;&lt;/th&gt;
      &lt;/tr&gt;
  
  @foreach (var item in Model) {
      &lt;tr&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.ReviewID)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Recomendation)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.AvoidOrBuy)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.Score)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.GameIDFK)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.DisplayFor(modelItem =&gt; item.UserName)
          &lt;/td&gt;
          &lt;td&gt;
              @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
              @Html.ActionLink("Details", "Details", new {  id=item.ReviewID }) |
              @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
          &lt;/td&gt;
      &lt;/tr&gt;
  }
  
  &lt;/table&gt;
  </code></pre>
  
  <p>I want a way in which the GameIDFK shows the name of the game rather then a number my controller to show this information is basic will show you here:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using Games.Models;
  
  namespace Games.Controllers
  {
      public class ShowAllReviewsController : Controller
      {
          //
          // GET: /ShowAllReviews/
  
          public ActionResult Index()
          {
              using (var db = new gamezoneDBEntities())
              {
  
                  return View(db.tblReviews.ToList());
              }
          }
  
          //
          // GET: /ShowAllReviews/Details/5
  
          public ActionResult Details(int id)
          {
              return View();
          }
  
          //
          // GET: /ShowAllReviews/Create
  
          public ActionResult Create()
          {
              return View();
          } 
  
          //
          // POST: /ShowAllReviews/Create
  
          [HttpPost]
          public ActionResult Create(FormCollection collection)
          {
              try
              {
                  // TODO: Add insert logic here
  
                  return RedirectToAction("Index");
              }
              catch
              {
                  return View();
              }
          }
  
          //
          // GET: /ShowAllReviews/Edit/5
  
          public ActionResult Edit(int id)
          {
              return View();
          }
  
          //
          // POST: /ShowAllReviews/Edit/5
  
          [HttpPost]
          public ActionResult Edit(int id, FormCollection collection)
          {
              try
              {
                  // TODO: Add update logic here
  
                  return RedirectToAction("Index");
              }
              catch
              {
                  return View();
              }
          }
  
          //
          // GET: /ShowAllReviews/Delete/5
  
          public ActionResult Delete(int id)
          {
              return View();
          }
  
          //
          // POST: /ShowAllReviews/Delete/5
  
          [HttpPost]
          public ActionResult Delete(int id, FormCollection collection)
          {
              try
              {
                  // TODO: Add delete logic here
  
                  return RedirectToAction("Index");
              }
              catch
              {
                  return View();
              }
          }
      }
  }
  </code></pre>
  
  <p>Is there a way in which i can obtain the game Foreign Key as this site is going to be used for new coming gamers and I want tos how which games are good play dont want a user clicking on a review and seeing just a number and no game name.</p>
  
  <p>Can you please help</p>
  
  <p>EDIT:</p>
  
  <p>I used the following in my view:</p>
  
  <pre><code>@Html.DisplayFor(modelItem =&gt; item.tblGame.GameName)
  </code></pre>
  
  <p>But it crashses and gives the following error:</p>
  
  <pre><code>The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <pre><code>namespace Games.Models
  {
      using System;
      using System.Collections.Generic;
  
      public partial class tblReview
      {
          public int ReviewID { get; set; }
          public string Recomendation { get; set; }
          public string AvoidOrBuy { get; set; }
          public string Score { get; set; }
          public int GameIDFK { get; set; }
          public string UserName { get; set; }
  
          public virtual tblGame tblGame { get; set; }
      }
  </code></pre>