tags:

views:

92

answers:

3

when specifying the src of an img tag, must i convert the relative path to absolute? please post examples and why not use runat="Server"

+3  A: 
<img src="<%=Url.Content("~")%>MyImageFolder/logo.png"/>
Josh Pearce
+1  A: 

runat=server creates a server control in the code behind, it is not really a usefull concept in MVC where you would not want to access properties of the control on the server.

Pharabus
+4  A: 

Because ASP.NET MVC views are in a separate folder, your best option is to use the

  <%= Url.Content("~/ImagesFolder/image.gif") %>

to get the exact path of the image.

All Url.Content does is return the exact path of a specific file using its relative url so it can be used for ANY file in your web application (.js .css .txt etc.).

Alternatively, a better implementation for images is Html.Image() which is available in the MVC Futures (I can't find the .dll link) and I think in the new version of ASP.NET MVC

If you can't find them, check out this post

http://stackoverflow.com/questions/509352/where-is-html-image-in-asp-net-mvc-rc/509396#509396

Baddie