title: Trouble passing ViewModel to Partial View
body: <p><strong>My ViewModel class (ItemViewModel.cs) looks like this:</strong></p>
  
  <p>public class ItemViewModel
  {</p>
  
  <pre><code>public ItemViewModel(xxx.Product product)
  {
      this.product = product;
  }
  
  private readonly xxx.xxx.Product product;
  private readonly Pers pers;
  private readonly Item item;
  
  public xxx.xxx.Product Product
  {
      get{ return product;}
  }
  
  public Item Item
  {
      get { return item; }
  }
  
  public ItemList Items
  {
      get { return product.Items; }
  }
  
  public Pers Pers
  {
      get { return pers; }
      set { value = pers; }
  }
  
  public PersList PersList
  {
      get { return product.PersList; }
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>The view has this code defined in it</strong> (I took out some other case lines, just to show one of them as an example):</p>
  
  <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Views/Shared/MasterPages/Item.Master" Inherits="System.Web.Mvc.ViewPage&lt;xxx.ViewModels.ItemViewModel&gt;" %&gt;
  
      &lt;%  foreach (Pers p in Model.Perslist)
          {
              switch(p.DispType)
              {
                  case DisType.Dropdown:
                      Model.Pers = p;
                      Html.RenderPartial("~/Views/Shared/Controls/Custom/PForm/DropDown.ascx",*Model);
                      break;
              }
          }
      %&gt;
  </code></pre>
  
  <p><strong>And the RenderPartial looks like this:</strong></p>
  
  <pre><code>&lt;fieldset&gt;
      &lt;div class="xxx"&gt;
          &lt;span class="xxx"&gt;*&lt;/span&gt;&lt;label&gt;&lt;%=Model.Pers.Name %&gt;&lt;/label&gt;
          &lt;p class="xxx"&gt;&lt;%=Model.Pers.Info %&gt;&lt;/p&gt;
      &lt;/div&gt;
      &lt;div class="formField"&gt;&lt;% Html.DropDownList(Model.Pers.Name, new SelectList(Model.Items[0].DropdownItems));%&gt;&lt;/div&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>The problem or dilemma I'm having is I not only need the p from the foreach but the entire ItemViewModel instance that was originally passed to my View.  Because I need to use the Pers in that foreach as well as be able to reference the Items.  So what I tried is to set the Pers property of the ItemViewModel class instance to the current p in the foreach.  Then tried to send the whole Model (now that I have that Pers set on the property) which is of type ItemViewModel so that I can now use the property Pers on that object and also still be able to reference the Items property that was populated already when it hit the View.</p>
  
  <p><strong>So when the page renders I get:</strong></p>
  
  <p>System.NullReferenceException: Object reference not set to an instance of an object.
  for this line:</p>
  
  <pre><code>&lt;span class="xxx"&gt;*&lt;/span&gt;&lt;label&gt;&lt;%=Model.Pers.Name %&gt;&lt;/label&gt;
  </code></pre>
  
  <p>So far I'm unsuccesful because I still get a null reference error on the property Pers when I attempt to use the ITemViewModel in my Partial View.</p>