title: I can't get my Month, Day, Year dropdown lists to work from my ASP.NET MVC3 ViewModel
body: <p>I'm converting over to MVC 3 from Webforms and have been having some trouble teaching myself. I created a ViewModel which should populate 3 separate select lists with Month, Day, Year values within my _Header. I think I have a structure issue. The end result is that I cause an unhandled exception in the www service on my machine and Visual Studio pops up and wants me to debug it.  Any help would be greatly appreciated!</p>
  
  <p>Here's my code.</p>
  
  <p>DateSearchViewModel.cs</p>
  
  <pre><code>namespace DH.ViewModels
  {
      public class DateSearchViewModel
      {
          //MONTH DROPDOWN LIST
          public class MonthViewModel
          {
             public int ID { set; get; }
             public string Month { set; get; }
          }       
  
          private List&lt;MonthViewModel&gt; _months;
          public List&lt;MonthViewModel&gt; Months
          {
              get
              {
                  if (_months == null)
                  {
                      _months = new List&lt;MonthViewModel&gt;();
                      _months.Add(new MonthViewModel { ID = 1, Month = "Jan" });
                      _months.Add(new MonthViewModel { ID = 2, Month = "Feb" });
                      _months.Add(new MonthViewModel { ID = 3, Month = "Mar" });
                      _months.Add(new MonthViewModel { ID = 4, Month = "Apr" });
                      _months.Add(new MonthViewModel { ID = 5, Month = "May" });
                      _months.Add(new MonthViewModel { ID = 6, Month = "Jun" });
                      _months.Add(new MonthViewModel { ID = 7, Month = "Jul" });
                      _months.Add(new MonthViewModel { ID = 8, Month = "Aug" });
                      _months.Add(new MonthViewModel { ID = 9, Month = "Sep" });
                      _months.Add(new MonthViewModel { ID = 10, Month = "Oct" });
                      _months.Add(new MonthViewModel { ID = 11, Month = "Nov" });
                      _months.Add(new MonthViewModel { ID = 12, Month = "Dec" });
                  }
                  return _months;
              }
          }
          public int SelectedMonthID { set; get; }
  
  
          //DAY DROPDOWN LIST
          public class DayViewModel
          {
              public int ID { set; get; }
              public string Day { set; get; }
          }
          private List&lt;DayViewModel&gt; _days;
          public List&lt;DayViewModel&gt; Days
          {
              get
              {
                  if (_days == null)
                  {
                      _days = new List&lt;DayViewModel&gt;();
                      _days.Add(new DayViewModel { ID = 1, Day = "1" });
                      _days.Add(new DayViewModel { ID = 2, Day = "2" });
                      _days.Add(new DayViewModel { ID = 3, Day = "3" });
                      _days.Add(new DayViewModel { ID = 4, Day = "4" });
                      _days.Add(new DayViewModel { ID = 5, Day = "5" });
                      _days.Add(new DayViewModel { ID = 6, Day = "6" });
                      _days.Add(new DayViewModel { ID = 7, Day = "7" });
                      _days.Add(new DayViewModel { ID = 8, Day = "8" });
                      _days.Add(new DayViewModel { ID = 9, Day = "9" });
                      _days.Add(new DayViewModel { ID = 10, Day = "10" });
                      _days.Add(new DayViewModel { ID = 11, Day = "11" });
                      _days.Add(new DayViewModel { ID = 12, Day = "12" });
                      _days.Add(new DayViewModel { ID = 1, Day = "13" });
                      _days.Add(new DayViewModel { ID = 2, Day = "14" });
                      _days.Add(new DayViewModel { ID = 3, Day = "15" });
                      _days.Add(new DayViewModel { ID = 4, Day = "16" });
                      _days.Add(new DayViewModel { ID = 5, Day = "17" });
                      _days.Add(new DayViewModel { ID = 6, Day = "18" });
                      _days.Add(new DayViewModel { ID = 7, Day = "19" });
                      _days.Add(new DayViewModel { ID = 8, Day = "20" });
                      _days.Add(new DayViewModel { ID = 8, Day = "21" });
                      _days.Add(new DayViewModel { ID = 8, Day = "22" });
                      _days.Add(new DayViewModel { ID = 8, Day = "23" });
                      _days.Add(new DayViewModel { ID = 8, Day = "24" });
                      _days.Add(new DayViewModel { ID = 8, Day = "25" });
                      _days.Add(new DayViewModel { ID = 8, Day = "26" });
                      _days.Add(new DayViewModel { ID = 8, Day = "27" });
                      _days.Add(new DayViewModel { ID = 8, Day = "28" });
                      _days.Add(new DayViewModel { ID = 8, Day = "29" });
                      _days.Add(new DayViewModel { ID = 8, Day = "30" });
                      _days.Add(new DayViewModel { ID = 8, Day = "31" });
                  }
                  return _days;
              }
          }
          public int SelectedDayID { set; get; }
  
  
          //YEAR DROPDOWN LIST
          public class YearViewModel
          {
              public int ID { set; get; }
              public string Year { set; get; }
          }
          private List&lt;YearViewModel&gt; _years;
          public List&lt;YearViewModel&gt; Years
          {
              get
              {
                  if (_years == null)
                  {
                      _years = new List&lt;YearViewModel&gt;();
                      _years.Add(new YearViewModel { ID = 1, Year = "2009" });
                      _years.Add(new YearViewModel { ID = 2, Year = "2010" });
                      _years.Add(new YearViewModel { ID = 3, Year = "2011" });
                      _years.Add(new YearViewModel { ID = 4, Year = "2012" });
                  }
                  return _years;
              }
          }    
          public int SelectedYearID { set; get; }
      }
  }
  </code></pre>
  
  <p>CommonController.cs:</p>
  
  <pre><code>[ChildActionOnly]
  public ActionResult _Header()
  {
      DateSearchViewModel DateVM = new DateSearchViewModel();
      return View(DateVM);
  }
  </code></pre>
  
  <p>_Header.cshtml:</p>
  
  <pre><code>@model DH.ViewModels.DateSearchViewModel
  
  @Html.DropDownListFor(x =&gt; x.SelectedMonthID, new SelectList(Model.Months, "ID", "Month"), "--Select--")
  @Html.DropDownListFor(x =&gt; x.SelectedDayID, new SelectList(Model.Days, "ID", "Day"), "--Select--")
  @Html.DropDownListFor(x =&gt; x.SelectedYearID, new SelectList(Model.Years, "ID", "Year"), "--Select--")
  </code></pre>
  
  <p>_Layout.cshtml:</p>
  
  <pre><code>@{Html.RenderAction("_Header", "Common");}
  </code></pre>