什么是一个asp.net MVC 4项目中引用图像的正确方法? [英] What is the correct way to reference an image in an asp.net mvc 4 project?

查看:473
本文介绍了什么是一个asp.net MVC 4项目中引用图像的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有看起来像这样的图像引用: 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助手与蒂尔达 标记(它可以解决应用程序的根目录):

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆