asp.net-mvc 你在哪里存储 asp.net mvc 项目的图像以及你如何从 site.master 引用它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1064786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where do you store images for asp.net mvc projects and how do you reference them from site.master
提问by leora
I have a new asp.net mvc project and i am trying to figure out the best place to store images and also how i would reference them from site.master (in cases where i have a header images that i want to show up on all pages).
我有一个新的 asp.net mvc 项目,我试图找出存储图像的最佳位置,以及如何从 site.master 引用它们(如果我有一个标题图像,我想在所有页)。
Suggestions or best practices?
建议或最佳实践?
回答by A Salcedo
What I generally do is create an "Images" folder inside my Content folder. Where you place your images is really up to you, as long as you are consistent.
我通常做的是在我的内容文件夹中创建一个“图像”文件夹。只要您保持一致,您放置图像的位置完全取决于您。
Referencing these images from your Site.Master is the same as if you referenced it from any view:
从 Site.Master 引用这些图像与从任何视图引用它是一样的:
<img src="/Content/Images/mylogo.png" />


回答by zacharydl
<img src="@Url.Content("~/Content/Images/logo.png")" />
Using this in a Razor view on MVC 5. Images are stored in /Content/Images.
在 MVC 5 的 Razor 视图中使用它。图像存储在 /Content/Images 中。
回答by mxmissile
<%=Html.Image("~/Content/Images/xxx.png")%>
This resolves from wherever you are in the site hierarchy. Html.Image is a part of the the Microsoft.Web.Mvc futures assembly.
这可以从您在站点层次结构中的任何位置解析。Html.Image 是 Microsoft.Web.Mvc 期货程序集的一部分。
回答by Fred
or in mvc2:
或在 mvc2 中:
<img src="<%: Url.Content("~/Images2/landingMain/safety.png") %>" alt="safety" />
回答by vijay chauhan
U must put all your images in Content Folder like :- Content-->Images-->.IMG files and same as style sheet files Content Folder like Content-->.css hence it easily load the images and css otherwise it is not executed in proper manner.
你必须把所有的图像放在内容文件夹中,如:-内容-->图像-->.IMG文件和样式表文件内容文件夹一样内容-->.css因此它很容易加载图像和css,否则它不是以适当的方式执行。

