0

I am attempting to make a photo gallery asp.net MVC website, and part of that involves the setting of the src to a local folder that contains images.

@model MyProj.Models.PhotoIndexViewModel

<div class="row" id="tableSearch">
    @foreach (MyProj.Models.VideoModel photo in Model.PImgList)
    {
        <div class="col-sm-3 thumbnail">
                @Html.DisplayFor(model => photo.Title)
                <a href=@Url.Action("View", new { id = photo.Id })>
    <img class="img-responsive"src="@Url.Content(photo.ThumbNailPrev)" alt=@photo.Id /></a>
                @Html.HiddenFor(m => m.searchTerm)
                @Html.Partial("_Tags", photo)
        </div>
    }
</div>

The ThumbNailPrev is "~/Pics/.jpg", which relates to a folder in the main part of the project. The issue is that the image does not appear. When I check the image using inspector is says it isn't found at /Pics/(photoid)/jpg. I don't understand why it is doing this, as my pics and the image itself are present at that location. I have also made sure to include the folder in my project, but it still doesn't seem to find the image.

UPDATE: I just tried something and confirmed it is something to do with the way I'm calling the path from the database. As if I hard code the EXACT same string as the one in the database it works. The question now is why does that work?

Rasen244
  • 137
  • 1
  • 2
  • 11
  • could be an issue related to relative path. Try this http://stackoverflow.com/questions/317315/asp-net-mvc-relative-paths – Sateesh Pagolu Sep 06 '15 at 01:01
  • if you copied this directly /Pics//jpg. there's an extra forward slash between pics and jpg – muckeypuck Sep 06 '15 at 01:03
  • DarkKnight: That is how my path is formatted, the ONLY difference is that I call it from the database, instead of hard coding it in the html. Also see update. – Rasen244 Sep 06 '15 at 01:07
  • muckeypuck: that was just a coincidental escape sequence of some kind with SO's posting system. Changing it to () seems to have eliminated the second /. Just to clarify there is NOT a second / in code. – Rasen244 Sep 06 '15 at 01:12
  • try changing @Url.Content(photo.ThumbNailPrev) to @photo.ThumbNailPrev – muckeypuck Sep 06 '15 at 01:12
  • Nope, I added the @Url.Content based on the same article Dark Knight recommended. I attempted it again just now without the Url.Content, and it still says the image was not found, just includes the ~ in front according to the inspector. – Rasen244 Sep 06 '15 at 01:17

1 Answers1

0

For want of a letter.. I finally determined the problem, and it was a pretty dumb one. In code I am saving a jpEg image, but calling it via jpg. After changing the .jpg to .jpeg in the view everything works... If you are having a similar problem, check and make certain the file extension is correct.

Rasen244
  • 137
  • 1
  • 2
  • 11