title: How to bind data to layout template in ASP.NET MVC Razor
body: <p>I am building a Book Store website with ASP.NET MVC 5, Razor, EntityFramework
  My entities</p>
  
  <pre><code>Category {
      int CateID,
      string CateName
  }
  
  Book {
      int BookID,
      int BookName
  }
  </code></pre>
  
  <p>My _Layout.cshtml have a sidebar (left menu), which display all of categories from database (same for all page).
  I have two Controller: HomeController and BookController, all the views of these controls will
  use the above layout template.
  I thought about UserControl, I create a UserControl name SideBarUserControl</p>
  
  <pre><code>@model List&lt;Category&gt;
   @if (ModelCount &gt; 0)
      {
      &lt;ul&gt;
          foreach (var l in Model)
          {
              &lt;li&gt;&lt;a href=""&gt;@l.CateName&lt;/a&gt;&lt;/li&gt;
          }
      &lt;/ul&gt;
      }
  </code></pre>
  
  <p>And in the Home/Index's view:</p>
  
  <pre><code>@Html.Partial("_SideBarUserControl")
  </code></pre>
  
  <p>But I don't know exactly where to put the binding code for it. Does it useful if I have a BaseController, which HomeController and
  BookController extended from it.</p>