您在哪里存储 asp.net mvc 项目的图像,以及如何从 site.master 引用它们

我有一个新的 asp.net mvc 项目,我试图找出最好的地方来存储图像,还有我将如何引用他们从 site.master (在情况下,我有一个头图像,我想显示在所有页面)。

建议还是最佳做法?

102067 次浏览

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:

<img src="/Content/Images/mylogo.png" />

alt text

<%=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.

or in mvc2:

<img src="<%: Url.Content("~/Images2/landingMain/safety.png") %>" alt="safety" />
<img src="@Url.Content("~/Content/Images/logo.png")" />

Using this in a Razor view on MVC 5. Images are stored in /Content/Images.

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.