I have my index.cshtml with a image
< img id="u3430_img" src="Images/send.png">
And a folder Images inside myApp/Images
folder
if i access
works Ok. But if i use
The page try to look for the image in
So how I should define my src.
Aditional note: Beside the index.cshtml I also have an js file where a hover effect is add it to the image. And have same problem neither of those option work
$('#u3430_img').hover(
function () {
$(this).attr("src", "~/Images/send_hover.png");
},
function () {
$(this).attr("src", "Images/send.png");
}
);
The <img> tag has two required attributes: src - Specifies the path to the image.
The 'src' attribute in a tag is the path to an external file or resource that you want to link to your HTML document.
You can reference images in the top level of the project with the ~
.
<img src="~/Images/send.png">
Older versions of ASP.NET MVC needed a @Url.Content() around the path, as described here
Edit: If you want to update the path from Javascript, you can either specify an absolute path, or wrap it in @Url.Content()
.
$('#image').attr('src', '/Images/send.jpg');
$('#image').attr('src', '@Url.Content("~/Images/send.png")');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With