Reputation: 109
I have tried for more than two hours and I can not find an answer to this problem. I have this part of the code in a view strongly typed in MVC:
<td>
@foreach (var TitleBook in Directory.GetFiles(Server.MapPath("~/App_Data/Images"), "*.jpg"))
{
var fileName = Path.GetFileName(TitleBook);
if (Convert.ToInt32(fileName.Substring(0,3)) == item.IdBook)
{
<img src="@TitleBook" alt="Alternate Text" height="100" width="100">
}
}
</td>
The name of the image file is created so the three first characters in the filename are numbers.
When I run the code, I get the alternate message for the image in the hmtl view. However, the path to this image is well read and I know it because I can obtain it by doing inspect in the browser and calling only the src part of in another window which shows the image as expected (sorry for my English). The css is handled by the version of boostrap installed in VS2017. Could someone point to my error here?
Upvotes: 0
Views: 36
Reputation: 273179
Your titleBook
is a full physical path. But <img>
wants an URL.
Untested:
<img src="~/App_Data/Images/@fileName" alt="Alternate Text" height="100" width="100">
BTW: with Directory.GetFiles(..., $"{item.IdBook:D3}*.jpg"))
you wouldn't need the foreach loop.
Upvotes: 1