title: How to Render the categories in database on SQL server in _Layout.cshtml
body: <p>i am trying to show the categories in my database on <code>SQL</code> on the homepage of my <strong><code>MVC web</code></strong> , how to do that?
  I have this in my <code>_Layout.cshtml</code>:</p>
  
  <pre><code>&lt;div class="list-group"&gt;
                      &lt;a href="#" class="list-group-item"&gt;Category 1&lt;/a&gt;
                      &lt;a href="#" class="list-group-item"&gt;Category 2&lt;/a&gt;
                      &lt;a href="#" class="list-group-item"&gt;Category 3&lt;/a&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>this is my <code>Views/store/index.cshtml</code>:</p>
  
  <pre><code>@model IEnumerable&lt;MVCOnlineShop.Models.Category&gt;
  
  @{
      ViewBag.Title = "Store";
  }
  &lt;h3&gt;Browse Categories&lt;/h3&gt;
  &lt;p&gt;
      Select from @Model.Count()
      Categories:
  &lt;/p&gt;
  &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>this is my <code>StoreController</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 StoreController : Controller
      {
          OnlineStoreEntities storeDB = new OnlineStoreEntities();
          //
          // GET: /Store/
  
          public ActionResult Index()
          {
              var Categories = storeDB.Categories.ToList();
              return View(Categories);
          }
          //
          // GET: /Store/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: /Store/Details
          public ActionResult Details(int id)
          {
              var Product = storeDB.Products.Find(id);
  
              return View(Product);
          }
          //
          // GET: /Store/Browse?Category=Games
  
      }
  }
  </code></pre>
  
  <p>and this is my <code>Global.asax</code>:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Http;
  using System.Web.Mvc;
  using System.Web.Optimization;
  using System.Web.Routing;
  
  namespace MVCOnlineShop
  {
      // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
      // visit http://go.microsoft.com/?LinkId=9394801
  
      public class MvcApplication : System.Web.HttpApplication
      {
          protected void Application_Start()
          {
  
  
              WebApiConfig.Register(GlobalConfiguration.Configuration);
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
              RouteConfig.RegisterRoutes(RouteTable.Routes);
              BundleConfig.RegisterBundles(BundleTable.Bundles);
              AuthConfig.RegisterAuth();
          }
      }
  }
  </code></pre>