Reputation: 309
I'm having a problem displaying images that are not inside the application folder but rather in C:\tmp\Somename\somepic.jpg I have been searching and trying things out but to no avail.
What I have so far (that I think is related to this problem) is: In controller
public ActionResult Edit(int? id)
{
if (id.HasValue)
{
var model = GetItems(id.Value);
ViewBag.Images = Directory.GetFiles(WebConfigurationManager.AppSettings["itemPath"] + model.ContentId.ToString().Substring(0, 3) + "\\", model.ContentId + "*.jpg");
return View(model);
}
return View("Notfound", "Home");
}
and in the view
<div class="row">
@foreach (var item in ViewBag.Images)
{
<img src="@Url.Content(item)" alt="hello"/>
}
Any help would be appreciated.
Upvotes: 0
Views: 177
Reputation: 14581
The problem seems to be caused by using absolute file paths in URLs, e.g.
<img src="c:\tmp\myimage.jpg" />
This won't work for three reasons:
This is also covered in src absolute path problem
Upvotes: 2