简体   繁体   English

<Img src=“logo.png”>不在_Layout.cshtml中工作

[英]<Img src=“logo.png”> not working in _Layout.cshtml

I'm making a site in mvc-5. 我正在用mvc-5制作一个网站。 I copied my logo.png picture to Views/Shared folder (same as _Layout.cshtml) and the only thing i see on my site is the default-non-working-photo icon. 我将我的logo.png图片复制到Views / Shared文件夹(与_Layout.cshtml相同),我在网站上看到的唯一内容是默认的非工作照片图标。

<img src="logo.png">

Static files (asssets (css files, fonts, etc) and javascript files) should not be mixed with MVC folders/files. 静态文件(asssets(css文件,字体等)和javascript文件)不应与MVC文件夹/文件混合使用。 Common reasons are opinionated and, since ASP.NET MVC is an opinionated framework, you have to make some changes for that to work, and I would advise against that. 常见的原因是自以为是,因为ASP.NET MVC是一个固定的框架,你必须做一些改变才能工作,我建议不要这样做。

The easiest way for this to work is to use the Content and Scripts folder that are already provided by the ASP.NET MVC templates. 最简单的方法是使用ASP.NET MVC模板已提供的ContentScripts文件夹。

Image paths (and other paths as well; javascript, css, etc.) need to be relative to the root of the site. 图像路径(以及其他路径; javascript,css等)需要相对于站点的根目录。 So you need to set it as follows: src="~/Views/Shared/logo.png" 所以你需要设置如下: src="~/Views/Shared/logo.png"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM