Castielle
Castielle

Reputation: 435

Image not rendering correctly in ASP.NET MVC 3

I recently switched from MVC2 to MVC3 and my images are no longer rendering correctly on the development server.

Here is the code:

<img src="@Url.Content("/content/images/sign_up.png")" height="50" width="550" />

Please note I use 'img' instead of 'image in the actual code but I could not post that.

When I look at the rendered HTML it says

<img src="/content/images/sign_up.png" height="50" width="550" />

When I try the URL localhost/content/images/sign_up.png the image shows up correctly.

Am I doing something wrong with MVC3, or maybe I need to make an adjustment to the IIS server?

Upvotes: 0

Views: 1334

Answers (1)

Sergi Papaseit
Sergi Papaseit

Reputation: 16174

You are missing a ~ sign:

<img src="@Url.Content("~/content/images/sign_up.png")" 
    height="50" width="550" />

From MSDN:

Url.Content Converts a virtual (relative) path to an application absolute path.

But to do that, you need to tell it you're passing a virtual path, which is achieved with the ~ .

Upvotes: 1

Related Questions