title: How to show data from SQL database in _Layout.cshtml in MVC
body: <p>i am working on an <strong>MVC OnlineShop project</strong>, i made Category and products <strong>database</strong> in <code>SQL server</code>, now i want to show the categories from this database on the homepage of the web. I tried before creating a <strong>session</strong> and calling this <strong>session</strong> in the <code>_Layout.cshtml</code> , but i found that <strong>session</strong> is not a good idea to show categories on the homepage although it worked, because session is used mostly for cookies... 
  <strong><em>Question:</em></strong> is this the right way to do that, or any better idea to do so?
   i wrote this in my <code>Homecontroller.cs</code> :</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using MVCOnlineShop.Models;
  
  namespace MVCOnlineShop.Controllers
  {
      public class HomeController : Controller
      {
          OnlineStoreEntities storeDB = new OnlineStoreEntities();
          //
          // GET: /Home/
  
          public ActionResult Index()
          {
              var Categories = storeDB.Categories.ToList();
              return View(Categories);
          }
          //
          // GET: /Home/Browse
          public ActionResult Browse(string Category)
          {
              // Retrieve Category and its Associated Products from database
              var CategoryModel = storeDB.Categories.Include("Products")
                  .Single(g =&gt; g.CategoryName == Category);
  
              return View(CategoryModel);
          }
          //
          // GET: /Home/Details
          public ActionResult Details(int id)
          {
              var Product = storeDB.Products.Find(id);
  
              return View(Product);
          }
          //
          // GET: /Home/Browse?Category=Games
  
      }
  }
  </code></pre>
  
  <p>and made a <strong><em>PartialView</em></strong> in <code>Views/Home</code> called <code>CategoryLayout.cshtml</code>:</p>
  
  <pre><code>@model IEnumerable&lt;MVCOnlineShop.Models.Category&gt;
  
  @{
      ViewBag.Title = "Categories";
  }
  &lt;ul&gt;
      @foreach (var Category in Model)
      {
  
          &lt;li&gt;
              @Html.ActionLink(Category.CategoryName,
  "Browse", new { Category = Category.CategoryName })
          &lt;/li&gt;
      }
  &lt;/ul&gt;
  </code></pre>
  
  <p>and wrote this in my <code>_Layout.cshtml</code>:</p>
  
  <pre><code>&lt;div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"&gt;
  
                  &lt;ul class="nav navbar-nav"&gt;
  
                      &lt;div class="dropdown"&gt;
                          &lt;button class="dropbtn"&gt;@Html.Partial("CategoryLayout")&lt;/button&gt;
                          &lt;div class="dropdown-content"&gt;
                              &lt;a href="#"&gt;Link 1&lt;/a&gt;
                              &lt;a href="#"&gt;Link 2&lt;/a&gt;
                              &lt;a href="#"&gt;Link 3&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
  
  
                  &lt;/ul&gt;
                  }
  </code></pre>