Reputation: 21751
I have an MVC 3 application, and in some of the .cshtml, I am returning images. The problem is that when I run this using IIS, the server is looking in the wrong place for the image. (problem only happens with "real" IIS, not IIS Express, and not with Cassini)
Result: If I use IIS, I get image placeholders instead of my images. If I use IIS Express or Cassini, I have no problems.
I used Process Monitor to determine where the server was looking for the image, and it seems to be ignoring the Virtual Directory settings (so it is looking for the image under wwwRoot, instead of in my app's virtual directory)
Code example from the cshtml file:
<ul>@foreach (var entity in this.Model)
{<li>
@Html.ActionLink(ShortDescription, "Index", "Search", new { entityName = entity.Value.UrlName }, null)
<img src="../../Content/themes/blue/EntityBullet.png" />
</li>}</ul>
I bet that either I'm missing a routing rule, or I'm doing something wrong with the img tag. Any clues?
Upvotes: 2
Views: 148
Reputation: 5333
use this inside your src attribute in image tag:
<img src="@Url.Content("~/content/themes/blue/image.png")" alt="" />
Upvotes: 4
Reputation: 76258
Use this (assuming Content
folder is directly under your site root):
<img src="@Url.Content("~/Content/themes/blue/EntityBullet.png")" />
Upvotes: 5