本文介绍了ASP.NET MVC4捆绑单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用MVC4中的新捆绑功能来捆绑单个文件?我知道捆绑单个文件没有多大意义,但我想使用服务器端压缩,并让MVC在URL的末尾附加一个哈希以进行缓存.
Is there a way to bundle a single file using the new bundling features in MVC4? I know bundling a single file doesn't make much sense but I'd like to use server-side minification and let MVC append a hash on to the end of the URL for caching purposes.
我已经尝试过@Scripts.Url("~/Scripts/myscript.js")
,但是它似乎没有用.
I've tried the @Scripts.Url("~/Scripts/myscript.js")
but it doesn't appear to work.
推荐答案
在包配置中,定义仅包含此文件的包:
Well, define a bundle containing only this file in your bundle config:
bundles.Add(
new ScriptBundle("~/bundles/myscript").Include("~/Scripts/myscript.js")
);
,然后通过名称引用在您的视图中使用它:
and then use it in your view by referencing it by name:
@Scripts.Render("~/bundles/myscript")
这篇关于ASP.NET MVC4捆绑单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!