title: ViewData not being passed to View
body: <p>I'm trying to send a <code>String</code> to the controller, via AJAX, and use it in a View that will be returned by the Controller:</p>
  
  <p><strong>Index.cshtml</strong></p>
  
  <pre><code>&lt;div id="apts"&gt;&lt;/div&gt;
  &lt;script&gt;
      $(document).ready(function(){
          $.post("/Apt",{"Date": "05/29/2015"},function(response){
              $("#apts").html(response);
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Controller.cs</strong></p>
  
  <pre><code>...
  public ActionResult Apt()
  {
      String date = DateTime.Today.ToString("MM/dd/yyyy");
      if (!String.IsNullOrEmpty(Request.Form["Date"]))
      {
          date = Request.Form["Date"];
      }
      ViewData["Date"] = date;
      return PartialView("~/Shared/_DisplaySection.cshtml");
  }
  </code></pre>
  
  <p><strong>_DisplaySection.cshtml</strong></p>
  
  <pre><code>@inherits System.Web.Mvc.WebViewPage
  @using System.Web.Mvc
  @using MySite.Models
  @{
      ViewPage VP = new ViewPage();
      // error is here: Object reference not set to an instance of an object.
      String date = VP.ViewData["Date"].ToString();
      MySite.Models.DisplaySection DW = new DisplaySection(date); 
  }
  
  @foreach(var a in DW.data)
  {
      &lt;div&gt;@a["name"]&lt;/div&gt;
  }
  </code></pre>
  
  <p>The error I'm getting is on <code>VP.ViewData["Date"].ToString()</code>,</p>
  
  <blockquote>
    <p>Object reference not set to an instance of an object.</p>
  </blockquote>
  
  <p>I searched for the error and found a couple of articles (<a href="https://stackoverflow.com/questions/11419753/object-reference-not-set-to-an-instance-of-an-object-partial-view">1</a>, <a href="https://stackoverflow.com/questions/8753340/how-to-pass-values-from-controller-to-view-in-asp-net/8753352#8753352">2</a>). They say I need to do a null check, but the way the controller is set up, ViewData["date"] should never be null, and I'd like to keep that logic in the Controller.</p>
  
  <p>Also, I found <a href="https://stackoverflow.com/questions/3979774/mvc-error-object-reference-not-set-to-an-instance-of-an-object">this</a>, but they are creating an instance of the model in the Controller, rather than the View.</p>
  
  <p>Is there a better way to pass this String besides ViewData? If not, how can I fix this?</p>