0

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?

1
  • How exactly are they rendered? Commented Apr 6, 2011 at 9:12

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I can't believe I spent hours on something so simple. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.