Im having a problem showing my images from a folder within my app. I have been looking a bit around and found this thread Display all images in a folder in MVC. With a foreach.
I have tried to implement the suggestion with the viewmodel and my code looks like this.
ViewModel
public class ListBooksViewModel
{
public IEnumerable<string> Images { get; set; }
}
Controller
public ActionResult _ListBooks()
{
var model = new ListBooksViewModel()
{
Images = Directory.EnumerateFiles(Server.MapPath("~/BookImageStorage")).Select(fn =>"~/BookImageStorage" + Path.GetFileName(fn))
};
return PartialView(model);
}
View
@model How.ViewModels.ListBooksViewModel
@foreach (var image in Model.Images)
{
<img src="@Url.Content(image)" />
}
My problem is I dont get any of the picture shown, I do however get the icon for an image for every image in my folder, and no error.. Can anyone explain to me why this is happening and help me fix the issue.
Thx and merry Christmas to those of you celebrate it..