2014-11-20 108 views
1

在我们的页面之一,我们有一个不合理的数量的jquery推入一个脚本标记。我试图通过将代码分离成几个独立的.js文件并使用ASP MVC 4 ScriptBundle来清理一些东西。ASP MVC 4捆绑不加载自定义js脚本

但是,Chrome显示只显示一个正在加载的脚本,该脚本有一个奇怪的名称,看起来有点像GUID。

enter image description here

如果我选择这个剧本,我可以看到,只有第一个.js文件中加载的包文件。第二个文件完全丢失。

BundleConfig脚本的

public class BundleConfig 
{ 
    // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725 
    public static void RegisterBundles(BundleCollection bundles) 
    { 
     bundles.Add(new ScriptBundle("~/bundles/AgentTransmission").Include(
        "~/Scripts/AgentTransmission/SetFields.js", 
        "~/Scripts/AgentTransmission/MarketingDivision.js")); 
    . 
    . 
    } 
} 

屏幕截图文件夹

enter image description here

.cshtml创建文件(查看)

@model MonetModelFromDb.Models.AgentTransmission 

@{ 
    ViewBag.Title = "Create new Agent"; 
} 


<div> 

    <meta http-equiv="cache-control" content="max-age=0" /> 
    <meta http-equiv="cache-control" content="no-cache" /> 
    <meta http-equiv="expires" content="0" /> 
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> 
    <meta http-equiv="pragma" content="no-cache" /> 

    <script src="@Url.Content("~/Scripts/jquery.maskedinput-1.3.1.js")" type="text/javascript"></script> 
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment-with-locales.min.js"></script> 
    @Scripts.Render("~/bundles/AgentTransmission") 

渲染HTML

<div> 

    <meta http-equiv="cache-control" content="max-age=0" /> 
    <meta http-equiv="cache-control" content="no-cache" /> 
    <meta http-equiv="expires" content="0" /> 
    <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> 
    <meta http-equiv="pragma" content="no-cache" /> 

    <script src="/Scripts/jquery.maskedinput-1.3.1.js" type="text/javascript"></script> 
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.3/moment-with-locales.min.js"></script> 
    <script src="/bundles/AgentTransmission?v=2D1TPLuuUcxrXmQ8AbdEoyTUVF8BEXja9e0nXKAzs9Q1"></script> 

编辑

FYI我也是在调试模式

+2

它看起来像是与优化运行结束。在'RegisterBundles()'中执行'BundleTable.EnableOptimizations = false'强制它进入调试状态。 – Jasen 2014-11-20 20:52:25

+0

工作。如果你想把它写成答案,我会接受。 Thx – NealR 2014-11-20 21:00:01

+0

更完整的答案[here](http://stackoverflow.com/questions/11944745/asp-net-bundles-how-to-disable-minification?rq=1) – Jasen 2014-11-20 22:51:11

回答

0

运行当你 “发布” 你的项目,并选择 “配置” 是 “释放”,系统将您的捆绑包与它们组合成一个具有“GUID”类名称的单个文件。如果您使用“调试”配置发布或构建您的项目,它会将每个单独的文件作为HTML中的单独文件保留在捆绑包中。

0

添加以下语句到RegisterBundles()

BundleTable.EnableOptimizations = false