3

I have an ASP.NET MVC application that works fine when I run it on Visual Studio. But when I publish it, all the styles dont seem to work. Are there any general guidelines on why styles dont work for an MVC application when published because right now I have no clue on what is happenning??

Any ideas and suggestions are appreciated!

5
  • By styles do you mean that none of the styles from your css are getting used? Commented Nov 22, 2011 at 15:43
  • 3
    View source in your browser, do the linked CSS style sheets show up? Commented Nov 22, 2011 at 15:44
  • @Maess actually some of them do while other's don't. Thats why I said are there any general guidelines on making the styles to work! Commented Nov 22, 2011 at 15:44
  • Are you using more than one .css file? Commented Nov 22, 2011 at 15:46
  • I right clicked the project and published onto a file system on the same box. I then add an application to IIS and it uses default app pool.... I am able to see the CSS folder in the published location that has all the css files. Anything that I am missing out? Commented Nov 22, 2011 at 15:47

3 Answers 3

4

There are many reasons why your css styles might not show up.

  • Caching: Maybe your browser use a cached version of your css file(s). Check with fiddler or clear the browsers cache
  • Wrong relativ path to the css file(s): You should specify relative paths when including css files in your views (use Url.Content("~/...") for getting the right url). This is an issue when you use not the same path on your IIS and your IDE.

But the first check in any cas is to run fiddler and see

  1. Is the browser requesting the right css file(s)
  2. Is the server returning the file or a 404, 304, ... status code
Sign up to request clarification or add additional context in comments.

2 Comments

Okay, I have checked using Fiddler and I am getting a status of 200 for the css files and the javascript.
Then you have to provide more detail. Show the css content that should be applied to an html element and show the result. As others suggested, you can use FireBug or Chrome to see which styles are applied to elements.
2

It is possible that you have defined the styles in a new file and have not included the new css file in your project (in Visual Studio .net).

VS.Net does not publish those files which are not part of the project.

2 Comments

I have actually inspected the element and this is what I see: background: none repeat scroll 0 0 transparent; But even though it says transparent the browser doesnt catch the style. It just shows a white background.
@Muthu good suggestion, happened to me more than once. @DotNetUser what happens if you try to add style like body { color: red; background-color: green; padding 300px; }, does that do anything?
1

Get Firebug, inspect the element that should have the style applied and see what CSS is actually present.

Take a look at the CSS Panel and see the CSS files that are being linked (click the down arrow in the master.css as shown in the image below).

enter image description here

Comments

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.