Where do you store images for asp.net mvc projects and how do you reference them from site.master

asp.net MvcImage

asp.net Mvc Problem Overview


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).

Suggestions or best practices?

asp.net Mvc Solutions


Solution 1 - asp.net Mvc

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

Solution 2 - asp.net Mvc

<img src="@Url.Content("~/Content/Images/logo.png")" />

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

Solution 3 - asp.net Mvc

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

Solution 4 - asp.net Mvc

or in mvc2:

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

Solution 5 - asp.net Mvc

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionleoraView Question on Stackoverflow
Solution 1 - asp.net MvcA SalcedoView Answer on Stackoverflow
Solution 2 - asp.net MvczacharydlView Answer on Stackoverflow
Solution 3 - asp.net MvcmxmissileView Answer on Stackoverflow
Solution 4 - asp.net MvcFryderyqView Answer on Stackoverflow
Solution 5 - asp.net Mvcvijay chauhanView Answer on Stackoverflow