Take the 2-minute tour ×

So I am trying to simply load a .css file from within the master page.

The master page Admin.Master and the css file AdminView.css are both in the /views/shared folder. I am sticking the following link tag in the section of my Master page.

I have tried both:

<link href="<%: ResolveUrl("AdminView.css")%>" rel="stylesheet" type="text/css"/>


<link href="AdminView.css" rel="stylesheet" type="text/css"/>

As well as every other combination (~/views/shared/adminview.css OR /adminview.css....etc)

and when viewing in Firebug what it loads, it always returns "Resource not found".

NOTE: I have double checked the name and spelling.

Its these trival stuff that shouldn't be this difficult.

share|improve this question
Try using <%:Url.Content("~/views/shared/adminview.css")> ~ symbol is only meaningful in server side script and you have to give paths relative to server root –  Muhammad Adeel Zahid Mar 6 '11 at 15:14
add comment

2 Answers

up vote 4 down vote accepted

You can't access resources in the Views folder directly from the web. You should put your content in the Content folder (or Content/Styles) and reference it from there. The Views folder is for the framework to use to find your Views, it isn't visible from the web.

<link href="<%: Url.Content( "~/content/styles/adminview.css" ) %>" ... />
share|improve this answer
So I have tried all these options and the Url.Content returns a URL of localurl.com/Account/Logon?ReturnURL=%2Content%2AdminViews.css. Which is wrong. However the error on the page is no longer stating "resource not found" but "Failed to load...." –  pghtech Mar 7 '11 at 3:52
@pghtech - Sounds like you are denying access to anonymous users in your web.config -- you shouldn't be. You should allow access and use the AuthorizeAttribute to control access to your controllers. I doubt if the Url helper is generating that URL, I suspect that it's getting a redirect from your site. –  tvanfosson Mar 7 '11 at 12:54
add comment
<link href="/views/shared/AdminView.css" rel="stylesheet" type="text/css"/>
share|improve this answer
add comment

Your Answer


