In ASP.NET core, static files are served from only the wwwroot folder by default. That means if you try to access a file from Contents/Images, which is your root, it won't work.
The good news is, You can configure the static file location as you wish. So update your Configure method in startup.
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
// Your existing code goes here
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), @"Content/Images")),
RequestPath = new PathString("/Images")
});
}
Now these images can be accessed from the browser like this yourSiteName/Images/imageFile.png
Now you can fix your view code to get image from this path.
@foreach (var item in Model)
{
<div>
<img src="@Url.Content("~/Images/"+item.Image)" />
</div>
}
Assuming item.Image value for each item in the collection has some value like this MyImage.png and you have an image called MyImage.png located at the Contents/Images which is in your application root (not in the wwwroot directory)
You may also consider moving the images to the wwwroot directory because the ASP.NET team added that directory for purposes like this ( static assets).