0

The problem here is that some views (not all of them) can't access to some css&js files(not all of them) ("404 Not found" error).
For exemple View of .../Details/Index/1 can't access to 1file css and 1file js (it can access all other files), but the View of .../Recherche/result can access to all files.
This problem happens when the user is connected and when not connected.
I didn't modifie the web.config file.
All View are related to one Layout, in there I inluded the css files:

<link href="Content/file.css" media="all" rel="stylesheet" type="text/css" />

And one last thing, all css files are in 1 folder and all js files are in 1 folder.

9
  • What's your code for including the CSS and JavaScript files? Commented Nov 29, 2015 at 22:28
  • 2
    You need to use absolute URLs. Commented Nov 29, 2015 at 22:32
  • updated ! (I don't know what do you mean by saying "check the console") Commented Nov 29, 2015 at 22:32
  • Open your browser's dev tools and look at the errors. Commented Nov 29, 2015 at 22:33
  • 2
    Possible duplicate of Absolute vs relative URLs Commented Nov 29, 2015 at 23:07

1 Answer 1

3

Start the path to the file with the tilde (~) character. Razor will converts a virtual (relative) path to an application absolute path.

<link href="~/Content/file.css" media="all" rel="stylesheet" type="text/css" />

If you are using an MVC version prior to MVC 4, you should use Url.Content helper method.

<link href="@Url.Content("~/Content/file.css")"  rel="stylesheet" type="text/css" />
Sign up to request clarification or add additional context in comments.

1 Comment

Correct! Also i strongly advice to use bundling feature of MVC. asp.net/mvc/overview/performance/bundling-and-minification

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.