title: How to show Category Name instead of Category ID in View from another table?
body: <p>Got a little problem with figuring it out, how can I achieve this...
  There are 2 db tables - Category and Product.
  <a href="https://i.stack.imgur.com/wNpfu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wNpfu.jpg" alt=""></a></p>
  
  <p>In my Kategoria column I want to show exactly name of the category, not ID. Below my model classes.</p>
  
  <p>Product.cs</p>
  
  <pre><code>public partial class Category
  {
      public int ID { get; set; }
      public int CategoryID { get; set; }
      public string Name { get; set; }
      public int ClientID { get; set; }
  }
  </code></pre>
  
  <p>Category.cs</p>
  
  <pre><code>public partial class Product
  {
      public int ID { get; set; }
      public int ProductID { get; set; }
      public string Name { get; set; }
      public int CategoryID { get; set; }
      public decimal Price { get; set; }
      public int Promotion { get; set; }
      public string Image1 { get; set; }
      public string Image2 { get; set; }
      public string Image3 { get; set; }
      public string Image4 { get; set; }
      public string Description { get; set; }
      public int ClientID { get; set; }
  
      public virtual Category Category { get; set; }
  }
  </code></pre>
  
  <p>And the ViewPart:</p>
  
  <pre><code>@Html.DisplayFor(modelItem =&gt; item.CategoryID)
  </code></pre>
  
  <p>When I type modelItem => item.Category.Name it doesn't work (column is empty). Any ideas how can i do this?</p>
  
  <p>Controller:</p>
  
  <pre><code>public class ProductsController : Controller
      {
          private ProductContext db = new ProductContext();
  
          private void LoadCreateViewBagData()
          {
              string domain = Request.Url.Host;
              int clientid = (from a in db.Client where a.Domain == domain select a.ID).First();
  
              int maxID = db.Product.Where(c =&gt; c.ClientID == clientid).Max(c =&gt; (int?)c.ProductID) ?? 0;
  
              ViewBag.MaxID = maxID + 1;
  
              IEnumerable&lt;SelectListItem&gt; categories = db.Category.Where(d =&gt; d.ClientID == clientid).Select(b =&gt; new SelectListItem { Text = b.Name, Value = b.CategoryID.ToString() });
  
              ViewData["categories"] = categories;
  
              ViewBag.ClientID = clientid;
          }
  
          // GET: Admin/Products
          public ActionResult Index()
          {
              string domain = Request.Url.Host;
              int clientid = (from a in db.Client where a.Domain == domain select a.ID).First();
  
              LoadCreateViewBagData();
  
              return View(db.Product.ToList().OrderByDescending(a =&gt; a.ProductID).Where(c =&gt; c.ClientID == clientid));
          }
  </code></pre>