如何添加类型= QUOT;文/ JavaScript的"在脚本标签使用System.Web.Optimization时 [英] How do I add type="text/javascript" to a script tag when using System.Web.Optimization
问题描述
我有以下
bundles.Add(new ScriptBundle("~/bundles/scripts/common").Include(
"~/Scripts/jquery.validationEngine.js",
"~/Scripts/common.js"));
生成
<script src="/bundles/scripts/common?v=9O0Yi3fV_GWpGyJQ_QYURiOYy6SEmxUQtkUVN4GXo2U1"></script>
在与渲染
<asp:PlaceHolder ID="PlaceHolderJs" runat="server">
<%: Scripts.Render("~/bundles/scripts/common") %>
</asp:PlaceHolder>
这是无效的HTML作为其缺少类型=文/ JavaScript的。如何让我的BundleCollection输出该元素在脚本标签?
Which is not valid HTML as its missing type="text/javascript". How do I make the BundleCollection output this element in the script tag?
推荐答案
一个办法是改变你的渲染你的脚本:
One way is to change how you render your scripts:
从:
@Scripts.Render("~/bundles/scripts/common")
要:
<script src="@BundleTable.Bundles.ResolveBundleUrl("~/bundles/scripts/common")" type="text/javascript"></script>
或取决于你如何实现捆绑,你可能需要:
Or depending on how you are implementing bundling, you may need:
<script src="@Microsoft.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/scripts/common")" type="text/javascript"></script>
或者Web窗体:
Or for web forms:
<script src="<%= Microsoft.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/scripts/common")%>" type="text/javascript"></script>
但如果有一种方法使用@ Script.Render我想看到它这样做。
Although if there is a way to do it using @Script.Render I'd like to see it.
更新:响应您的意见,如指定该SO回答,在 System.Web.Optimization
的pre-发布版本中,有一个名为 RenderFormat
选项,可以让你这样做,以及...但我觉得上面的东西更容易阅读的这种特殊情况下。
UPDATE: in response to your comments, as specified in this SO answer, in the pre-release version of System.Web.Optimization
, there is an option called RenderFormat
that will let you do this as well... but I think the stuff above is easier to read for this particular case.
这篇关于如何添加类型= QUOT;文/ JavaScript的&QUOT;在脚本标签使用System.Web.Optimization时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!