Displaying images Object reference not set to an instance of an object
<p>Hi everyone I am trying to display all the images I have in a folder and I get this error nullreference exception Additional information: Object reference not set to an instance of an object." when it gets to Model.Images, i put a break point on the foreach line and the model is empty even though there is images in the folder, any idea how to fix this?</p>

<p>Thanks for any help with this issue.</p>

<p>controller</p>

<pre><code> public ActionResult Getimages()
    {
        var model = new imagesModel()
        {
            Images = Directory.EnumerateFiles(Server.MapPath("~/Img"))
                              .Select(fn =&gt; "~/Img" + Path.GetFileName(fn))
        };
        return View(model);
    }
</code></pre>

<p>model</p>

<pre><code> public class imagesModel
{
    public IEnumerable&lt;string&gt; Images { get; set; }
}
</code></pre>

<p>View</p>

<pre><code>@model MyProject.Models.imagesModel

@foreach (var image in Model.Images)
{
&lt;img src = "@Url.Content(image)" alt = "image" /&gt;
}
</code></pre>