My goal is to display an image on the page from the one of the folders, for example ~/Content/Images/img_1.jpg
.
The image paths are saved inside an array that I successfully fetch from a DB. What I am struggling with is the fact that there are special characters in the passed command.
So I'd have something like @Url.Content("~/Content/Images/img_1.jpg")
to pass in the DB field and when it gets passed to JQuery .html()
it doesn't work properly and gives a 404. I looked into escaping the characters but I don't think that works. This might be a bad way of doing the whole thing though, so I am open to ideas on how to facilitate that dynamic image loading...
EDIT: I have figured a bit out. The DB will hold only the image name, not the full path. So only the escaping the pathname characters in JS in HTML context are left.
"<img src=/Content/Images/" (escape characters here) + metadata.imgSrc + " alt=" + metadata.title + " >";