使ASP.NET捆绑指定媒体=屏幕CSS包 [英] Make ASP.NET bundling specify media=screen for CSS bundle
问题描述
我只是尝试了ASP.NET 4.5捆绑和缩小,并遇到了一个问题。
I'm just trying out ASP.NET 4.5 bundling and minification, and ran into an issue.
我有大约10 css文件,其中2例在布局使用属性媒体=屏幕最初引用。
I've got around 10 css files, of which 2 were originally referenced in the layout using the attribute media="screen".
由于增加一个css来捆绑不允许您指定这样的属性应加语法(有道理的,因为该属性将适用于整个束),我希望能看到@Styles过载。渲染,让我到指定的HTML属性,如在其他HTML辅助,却是没有。
Since the syntax for adding a css to the bundle does not let you specify that such attribute should be added (makes sense, since the attribute would apply for the whole bundle), I was hoping to see an overload of @Styles.Render that would allow me to specify html attributes, like in other Html helpers, but there is none.
有是一个丑陋的解决方案,在其中,因为我知道创建束的URL,我可能只是手艺标记自己,但我会允许它来渲染失去由ASP.NET处理的缓存机制标签本身。
There is an ugly solution, in which since I know the url of the bundle created, i could just craft the tag myself, but I'd lose the caching mechanism that is handled by ASP.NET by allowing it to render the tag itself.
有没有办法做到这一点,我失去的东西吗?或者这只是设计团队的监督?
Is there a way to do this, am I missing something? Or is this just an oversight of the design team?
推荐答案
嗯,这是一个丑陋的黑客攻击,但希望球队将增加一个内置的方式做到这一点在下一个版本。
Well, it's an ugly hack, but hopefully the team will add a built-in way to do it in the next release.
这是我如何解决它,保持高速缓存字符串,并仍然能够在媒体属性添加到标签。
This is how I solved it, maintaining the caching string and still being able to add the media attribute to the tag.
@{
var cssMediaBundleUrl = BundleTable.Bundles.ResolveBundleUrl("~/stylesheets/mediacss", true);
}
<link href="@cssMediaBundleUrl" rel="stylesheet" type="text/css" media="screen" />
想我可以把它变成一个HTML帮手,以后和编辑就可以了。
Guess I can turn this into an Html helper, will do that later and edit.
这篇关于使ASP.NET捆绑指定媒体=屏幕CSS包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!