title: NullReferenceException when using foreach loop in Model
body: <p>I've been trying to display data from a database table by using <code>foreach</code>, however I am getting this error:</p>
  <blockquote>
  <p>An exception of type 'System.NullReferenceException' occurred in App_Web_tncl0rkz.dll but was not handled in user code`.</p>
  <p>Error at: @foreach (var img in Model)</p>
  </blockquote>
  <p>When I try to access the <code>View</code>, the application crashes resulting in mentioned error.</p>
  <p>This is my View's <code>HTML</code> code <em><code>C#</code> included as I am programming with visual studio</em></p>
  <pre><code>@model IEnumerable&lt;Common.Image&gt;
  ....
  &lt;table class=&quot;table&quot;&gt;
      &lt;tr&gt;
          &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.imagePath)&lt;/th&gt;
          ....
      &lt;/tr&gt;
      @foreach (var img in Model)
      { 
          &lt;tr&gt;
              &lt;td&gt;@Html.DisplayFor(imgItem =&gt; img.imagePath)&lt;/td&gt;
              ....
          &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>
  <p>This is my <code>Controller's</code> <code>C#</code> code.</p>
  <pre><code>[Authorize(Roles=&quot;Admin&quot;)]
  public ActionResult UsersGallery(string username)
  {
      ImagesBL imgBl = new ImagesBL();
      Image img = imgBl.GetImage(username);
      return View(img);
  }
  </code></pre>