Reputation: 393
I have a weird bug that just happened to me, it was working before but I changed something very small that broke everything.
So, I have an Image that I find in the DB and then render it to the view by building the image link. The thing is : Razor is unable to map it to the image.
I have made an mage to show you how weird it is.
As you can see, those are the exact same strings, one is mapped correctly, the other isn't. I wonder is there is some kind of format that I'm missing. If I do "Server.MapPath" to get the absolute path of the Image, then it maps it correctly but the access to the image is forbidden (because absolute path).
Upvotes: 1
Views: 740
Reputation: 11983
you can also use custom htmlhelper of image and use like this. @html.Image(@item.ImageName)
Upvotes: 0
Reputation: 49133
Razor is only applying this tilde-slash magic when the relative path is applied directly into some HTML element's attribute, not when it's part of some model property.
You'll have to use Url.Content
explicitly:
<img src="@Url.Content(Model.ProfilePicturePath)" />
Upvotes: 2