1

我有最困难的时间绑定工作在Asp.Net MVC。我设置了EnableOptimizations,以便在转移到prod之前测试捆绑包。与jQuery的MVC绑定不能在调试更多

这里是我的RegisterBundles

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

     bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
        "~/Scripts/jquery/jquery-ui.js")); 

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

     BundleTable.EnableOptimizations = true; 

这里是我的_layout

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

然而,当我的页面呈现,它具有以下JavaScript错误。这告诉我,jQuery的JavaScript没有加载。看来,html被返回。我相信当捆绑包试图检索js时,它实际上会再次返回我的登录页面。

SyntaxError: expected expression, got '<' jquery:2:0 
SyntaxError: expected expression, got '<' jqueryui:2:0 
SyntaxError: expected expression, got '<' jqueryval:2:0 

任何帮助,非常感谢。

+0

你创建使用默认的Visual Studio模板的项目? – Thanigainathan

回答

2

如果您正在保护站点的某些部分,那么您需要排除受保护的包的路径。

这里是另一个问题,这个问题的解决方案:https://stackoverflow.com/a/6304624/84395

+0

如果您使用绑定,则在调试和发布模式下脚本的路径可能会有所不同。您可能需要在您的调试web.config文件中的''在您的发行版web.config文件中以及'>'中进行访问。 – kbarton0