title: MVC Error: The model item passed into the dictionary is null
body: <p>I'm just trying to build a view but I'm getting the following error:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: The
    model item passed into the dictionary
    is null, but this dictionary requires
    a non-null model item of type
    'System.DateTime</p>
  </blockquote>
  
  <p>Now, I know why this is coming up, the particular field in the database <em>is</em> null, however it is supposed to be, as this is something that is edited at a later date. Here is my code:</p>
  
  <p><strong>Action</strong></p>
  
  <pre><code>public ActionResult View(Int64? Id)
      {
  
          ModelContainer ctn = new ModelContainer();
          var item = from t in ctn.Items where t.ItemID == Id select t;
          return View(Item.First());
      }
  </code></pre>
  
  <p><strong>Main View</strong></p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Administrator.Master" Inherits="System.Web.Mvc.ViewPage&lt;myApp.Data.Item&gt;" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&gt;
      View
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
  
      &lt;% Html.RenderPartial("Details", Model); %&gt;
  
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="Content3" ContentPlaceHolderID="Header" runat="server"&gt;
  &lt;h1&gt;Details - &lt;%= Model.MainItem %&gt;&lt;/h1&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>Partial View</strong></p>
  
  <pre><code>&lt;%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl&lt;myApp.Data.Item&gt;" %&gt;
  &lt;%@ Import Namespace="myApp.Supplier.Web.Extensions" %&gt;
  
      &lt;fieldset&gt;
  
          &lt;legend&gt;Information&lt;/legend&gt;
  
          &lt;div class="fieldset"&gt;
  
              &lt;%= Html.LabelFor(m =&gt; m.MainItem)%&gt;
              &lt;%= Html.DisplayFor(m =&gt; m.MainItem, "FormTextShort")%&gt;&lt;br /&gt;
              &lt;%= Html.LabelFor(m =&gt; m.Supplier.Name)%&gt;
              &lt;%= Html.DisplayFor(m =&gt; m.Supplier.Name, "FormTextShort")%&gt;&lt;br /&gt;
              &lt;%= Html.LabelFor(m =&gt; m.ProductCode)%&gt;
              &lt;%= Html.DisplayFor(m =&gt; m.ProductCode, "FormTextShort")%&gt;&lt;br /&gt;
              &lt;%= Html.LabelFor(m =&gt; m.Product.SubmissionDate)%&gt;
              &lt;%= Html.DisplayFor(m =&gt; m.Product.SubmissionDate, "FormDateShort")%&gt;&lt;br /&gt;
              &lt;%= Html.LabelFor(m =&gt; m.Product.SentForRepair)%&gt;
              &lt;%= Html.DisplayFor(m =&gt; m.Product.SentForRepair, "FormDateShort")%&gt;&lt;br /&gt;
           &lt;/div&gt;
  
      &lt;/fieldset&gt;
  </code></pre>
  
  <p>In this case, the x.Product.SentForRepair date is left null, because at the time of submission, it has not yet been sent away. I have other fields like this, e.g. totalCost, etc however for simplicity I have not included them here. If I comment out the SentForRepair lines, the View displays perfectly with the other information. </p>
  
  <p>I'd be so so grateful if someone could point me in the right direction as to how to get around this error!! :)</p>