Click here to Skip to main content
15,887,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am getting started with MVC4 Razor. I am looking to see the equivalent of

HTML
<img src="<%=strAppVirtualPath %>/images/logo.jpg" alt="[Logo]" />
in MVC.

Should some variant of this work? But how does it discriminate the + there?
HTML
<img src="@HttpRuntime.AppDomainAppVirtualPath+images/logo.jpg" alt="[Logo]" />
Posted
v2

I figured out the solution myself.

C#
@{
    var strLogoPath = HttpRuntime.AppDomainAppVirtualPath;
    strLogoPath = string.Format("{0}images/logo.jpg", strLogoPath);
 }
<img src="@strLogoPath" alt="[Logo]" />
 
Share this answer
 
Comments
fjdiewornncalwe 16-Apr-13 12:19pm    
I don't think you even need that much. Just put the image in as <img src="/images/logo.jpg" /> and it should work. No need to set the absolute path.
Marcus,

My only concern is this guy is the shared header between multiple pages.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900