Reputation: 93434
Is it possible to get the site root relative translation in the CSS file of an MVC3 app?
In the .cshtml, I can use:
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
However, in the CSS I need to access content such as:
background-image: url('/Content/images/banner.png');
I would like to be able to get the root like i can with the @Url.Content so i can do something like this (which obviously doesn't work):
background-image: url(@Url.Content("~/Content/images/banner.png"));
Upvotes: 4
Views: 1493
Reputation: 7075
Urls in css files are relative to the css file - it is not possible to specify the url relative?
If not then you will need to have ASP.NET process the file. You can either add a mapping to make all css files processed by the ASP.NET engine or to rename the css file into a file with with an extension that already is processed by ASP.NET - such as .aspx. You will probably also need a page directive to make it work...
Upvotes: 3