Reputation: 61
My mvc5 webApp can´t seem to display images if I run it on the virtual server, however if I run it locally it works.
So I have tried several approaches and none that allowed me to run the app on the virtual server or on my pc worked I have tried:
(these worked if I was running this locally)
Images/arrow.png
/Images/arrow.png
This path works for the virtual server but not locally.
webAPP/Images/arrow.png
I know about @Url.Action but I have a lot of different images, around 15, and I don´t know if using @Url.Action is a good idea for that many.
any small example would help tremendously!
Upvotes: 2
Views: 5034
Reputation: 5252
If you know the path to the images from the site root you can do the following in MVC:
@Url.Content("~/images/my-image.jpg")
The "~/" will map from the site root.
EDIT: If you're working within a JS file and struggling with relative paths maybe you could add a 'basepath' variable to the top of the file and work with that:
var basePath = "http://www.mywebsite.com/images";
Then in your code, your image URL returned would be something like:
var imgUrl = basePath + "/my-image.jpg";
Upvotes: 3