title: Partialview and passing data to layout MVC3
body: <p>i want to show categories to all pages by using layout and here my way:
  here my model (NewsCategoriesModel)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.ComponentModel.DataAnnotations;
  using System.Globalization;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Web.Security;
  
  
  namespace GiaoXuKeSat.Models
  {
      public class NewsCategoriesModel
      {
          public int NewsCategoriesID { get; set; }
          public string NewsCategoriesName { get; set; }
      }
  }
  </code></pre>
  
  <p>Here Partialview (_NewsCategories)</p>
  
  <pre><code>@using System.Linq;
  
  
  @using System.Linq;
  @model IEnumerable&lt;GiaoXuKeSat.Models.dms_NewsCategory&gt;
  
  @foreach (var item in Model) {
    &lt;ul id="dmsMenuULUL"&gt;
       &lt;li&gt;@item.NewsCategoriesName&lt;/li&gt;
  &lt;/ul&gt;     
  }
  </code></pre>
  
  <p>and i print that partialview to layout</p>
  
  <pre><code>@Html.Partial("_NewsCategories");
  </code></pre>
  
  <p>but i got Object reference not set to an instance of an object.
  at</p>
  
  <pre><code>@foreach (var item in Model) {
  </code></pre>