title: foreach (var item in Model), Object reference not set to an instance of an object
body: <p>I used the "List View" in the Controller to generate an storeList.cshtml file, within this view file, there is a line:</p>
  
  <pre><code>foreach (var item in Model) {}
  </code></pre>
  
  <p>When I run the app, this line keeps getting the "Nullreference" error, and the "Object reference not set to an instance of an object" error.</p>
  
  <p>I'm confused because:</p>
  
  <p>1) This view file is auto-generated; so why is it not correct?</p>
  
  <p>2) I've used the exact same way ("List View") and generated many other view files, and never encountered this problem.</p>
  
  <pre><code>&lt;table class="uk-table"&gt;
  &lt;tr&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.CategoryID)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.typeID)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.name)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.storeUrl)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.storedes)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.tags)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.image)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.metaTitle)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.metaDescription)
      &lt;/th&gt;
      &lt;th&gt;
          @Html.DisplayNameFor(model =&gt; model.popular)
      &lt;/th&gt;
      &lt;th&gt;&lt;/th&gt;
  &lt;/tr&gt;
  @foreach (var item in Model) {
  &lt;tr&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.CategoryID)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.typeID)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.name)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.storeUrl)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.storedes)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.tags)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.image)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.metaTitle)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.metaDescription)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.popular)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
          @Html.ActionLink("Details", "Details", new { id=item.id }) |
          @Html.ActionLink("Delete", "Delete", new { id=item.id })
      &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p>}</p>
  
  <p></p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code> public ActionResult storeList()
      {
          return View();
      }
  </code></pre>
  
  <p><strong>Model</strong></p>
  
  <pre><code> public partial class store
  {
      public store()
      {
          this.Reviews = new HashSet&lt;Review&gt;();
      }
  
      public int id { get; set; }
      public Nullable&lt;int&gt; CategoryID { get; set; }
      public Nullable&lt;int&gt; typeID { get; set; }
      public string name { get; set; }
      public string storeUrl { get; set; }
      public string storedes { get; set; }
      public string tags { get; set; }
      public string image { get; set; }
      public string metaTitle { get; set; }
      public string metaDescription { get; set; }
      public Nullable&lt;bool&gt; popular { get; set; }
  
      public virtual Category Category { get; set; }
      public virtual ICollection&lt;Review&gt; Reviews { get; set; }
      public virtual Type Type { get; set; }
  }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <p><strong>Object reference not set to an instance of an object.</strong></p>
  
  <p>Description: An unhandled exception occurred during the exec
  ution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: <strong>System.NullReferenceException: Object reference not set to an instance of an object.</strong></p>
  
  <p>let me know how to fix this?</p>
  
  <p>Thanks</p>