2014-03-26 108 views
3

我想呈現一個腳本包,但它是空的。爲什麼jqueryval包渲染爲空?

下面是BundleConfig.cs

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-{version}.js")); 

bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
        "~/Scripts/modernizr-*")); 

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
        "~/Scripts/bootstrap.js", 
        "~/Scripts/respond.js")); 

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
        "~/jquery.unobtrusive.ajax*", 
        "~/jquery.validate.unobtrusive.bootstrap*")); 

而且在我看來,劇本捆綁申報

@Scripts.Render("~/bundles/jquery") 
@Scripts.Render("~/bundles/bootstrap") 
@Scripts.Render("~/bundles/modernizr") 
@Scripts.Render("~/bundles/jqueryval") 

但是當我加載頁面時,jqueryval腳本出現空。

<script src="/bundles/jquery?v=Nsx6sB8o7LJCR51P5u-dfe-6LePnt87pD0P5VTJ-0wI1"></script> 

<script src="/bundles/bootstrap?v=XkxfR798CUJPhMhSd0B8VYgZWSNOTtLvz6047jf84wQ1"></script> 

<script src="/bundles/modernizr?v=K-FFpFNtIXPUlQamnX3qHX_A5r7TM2xbAgcuEmpm3O41"></script> 

<script src="/bundles/jqueryval?v="></script> 

Firefox中的調試器說,返回200個狀態檢索捆綁包的文件時,但文件大小爲0

回答

4

最有可能的,你的路是不正確的。這:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
        "~/jquery.unobtrusive.ajax*", 
        "~/jquery.validate.unobtrusive.bootstrap*")); 

應該

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
        "~/scripts/jquery.unobtrusive.ajax*", 
        "~/scripts/jquery.validate.unobtrusive.bootstrap*")); 

記住,~/映射到該網站的虛擬根目錄時,該路徑被解決,所以除非你把JavaScript文件在網站根目錄,這些路徑在你的包中不起作用。

+0

呃。隱藏在衆目睽睽下。謝謝。 – mvanella