MVC – Fixing those broken images

MVC is full of all sorts of wonderful pitfalls features.

While working on a site, if I loaded up the default site I was debugging (http://localhost:3316) with no controller or actions segments , and the images on the page appeared. When I went all fancy and used http://localhost:3316/Home, then the images broke, and there was much gnashing of teeth. And a little crying, but that was probably the hot sauce.

However, I found an excellent post on Peter Seale’s blog about using prepending a “~/” onto a link. And I found that life got better when I did that. So if I have this image URL:


That may not work because of the twists and turns that is MVC. If your images do break when navigating to a particular view from a different way, try the “~/” trick:


You may just leave happy. Maybe.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: