1

In MVC 2 I'm trying to display a image On my master page using CSS.

.menu .symbol-item  { background-image:url(Content/icons/page.png); }

The image is displaying when the URL is like

http://localhost:4745/Item

but it does not display when the URL is like

 http://localhost:4745/Item/Create

Both the pages use the same master page

1
  • Use an absolute path: .menu .symbol-item { background-image:url(/Content/icons/page.png); } Commented May 2, 2013 at 10:09

1 Answer 1

1

You need to use Url.Content in order to make sure your URL will resolve to the same place every time. To do this, that CSS needs to live in your view. First move it to your view, then do:

.menu .symbol-item  { background-image:url(@Url.Content("~/Content/icons/page.png"); }
Sign up to request clarification or add additional context in comments.

2 Comments

did not work. I used .menu .symbol-item { background-image:url(<%: Url.Content("~/Content/icons/page.png")%>); } but still the same result
@chamara what was the URL for the image in the browser? Check dev tools.

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.