How to reference an image tag
I'm studying Asp.Net MVC and I'm having trouble setting the URL of the tag
HTML:
<!-- menu profile quick info -->
<div class="profile">
<div class="profile_pic">
<img src="~/Views/Home/images/img.jpg" alt="..." class="img-circle profile_img">
</div>
<div class="profile_info">
<span>Welcome,</span>
<h2>John Doe</h2>
</div>
</div>
My doubt is, Is this right this URL: src="~/Views/Home/images/img.jpg"
?
My project hierarchy:
Because when executing, I am having the error:
1 answers
You may have already noticed that inside the Folder views there is a file web.config .
By default, this config restricts access to all files in this folder.
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
For sure you can change that, but it doesn't make sense. You can end up allowing anyone (good or bad) to have access to the views files.
The tip I give you is to put your images in subfolders in the Folder content, and use them with the path ~ / Content/Images/home / img1.png . Of course you have the option to create other folders as well, but I think that Content already serves that.