首页 > 解决方案 > Image isn't displaying

问题描述

I have a div property inside a form where I want to display an image.
But I can't manage to fix it. I get an HTTP ERROR 404.

My solution tree looks like:
MyProject
--Controllers
--img
----Logo.jpg
--Models
--Views
----Home
------Login.cshtml

Part of Login.cshtml, where I have the img property.

<div class="split left">
  <div class="centered">
    <img src="~/img/Logo.jpg">
  </div>
</div>

What I'm a doing wrong?
Thanks in advance for any help.

标签: c#htmlcssasp.net-mvcrazor

解决方案


您不能在img标记中使用波浪号 (~) 客户端,因为它无法解析根目录。

您需要使用页面中的相对路径:

<img src="../img/Logo.jpg">

如果要使用波浪号,则需要使用服务器端标记。


推荐阅读