Hodyr
Hodyr

Reputation: 53

Dot net, Some Views can't access css&js files

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.

Upvotes: 0

Views: 40

Answers (1)

Shyju
Shyju

Reputation: 218832

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" />

Upvotes: 3

Related Questions