问题描述
所以,我想简单地从母版页内加载.css文件。
So I am trying to simply load a .css file from within the master page.
母版页Admin.Master和CSS文件AdminView.css都在/视图/共享文件夹。我坚持下面的链接标签在我的母版页的部分。
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.
我已经试过两个:
<link href="<%: ResolveUrl("AdminView.css")%>" rel="stylesheet" type="text/css"/>
和
<link href="AdminView.css" rel="stylesheet" type="text/css"/>
除了其他所有组合(〜/查看/共享/ adminview.css或/adminview.css....etc)
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.
推荐答案
您不能访问资源视图直接从Web文件夹。你应该把你的内容在内容文件夹(或内容/样式),并从那里引用它。视图文件夹是框架用来寻找您的看法,它不是从网上看到。
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" ) %>" ... />
这篇关于不能让CSS在母版页加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!