什么是一个asp.net MVC 4项目中引用图像的正确方法? [英] What is the correct way to reference an image in an asp.net mvc 4 project?
问题描述
我有看起来像这样的图像引用: SRC =../../图像/ backup5.jpg
。这相匹配的项目结构。虽然在发布的版本,这些链接不工作。如果我通过删除../的形象路径更改为 SRC =../图像/ backup5.jpg
将正确显示。是什么让他们在这两个开发版本,并在发布的版本中运行引用这些图像的正确方法是什么?
I have image references that look like this: src="../../Images/backup5.jpg"
. This matches the project structure. Although in the published version, these links do not work. If i change the path to src="../Images/backup5.jpg"
by removing a "../" the image will display correctly. What is the correct way to reference these images so they work in both the development version and in the published version?
跟进,如何把这个看在CSS作为背景适用于:?
属性
Follow up, how should this look when used in css as a background:
attribute?
推荐答案
您应该使用<$c$c>Url.Content$c$c>助手与蒂尔达 〜
标记(它可以解决应用程序的根目录):
You should be using the Url.Content
helper with the tilda ~
marker (which resolves to the root of the application):
src="@Url.Content("~/Images/backup5.jpg")"
这篇关于什么是一个asp.net MVC 4项目中引用图像的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!