jQuery-vsdoc无法使用MVC4捆绑吗?和@ Scripts.Render在上面的_Layout.cshtml中包含时不起作用? [英] Jquery-vsdoc not working using MVC4 Bundling ? and @Scripts.Render not working when included above in _Layout.cshtml?

查看:169
本文介绍了jQuery-vsdoc无法使用MVC4捆绑吗?和@ Scripts.Render在上面的_Layout.cshtml中包含时不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我添加到BundleConfig中的vsdoc包,并在_Layout.cshtml中呈现了脚本.但是我无法让jquery intellisense在视图上工作.到目前为止,使它起作用的唯一方法是粘贴对使用Jquery的视图的引用.另一件事是,如果我在_Layout.cshtml中的</body>上方呈现脚本,那么即使是警报框也无法正常工作.但是,如果我在`< head>`标记中渲染它,它就可以工作.为什么 ?任何帮助将不胜感激-谢谢

** BundlesConfig **

Below is the vsdoc bundle I''ve added to BundleConfig, and have rendered the scripts in _Layout.cshtml. Yet I couldn''t get the jquery intellisense working on the views. The only way i''ve got it working thus far is by pasting a reference to the view where I''m using Jquery. The other thing is that even an alert box doesn''t work if I render the scripts above the `</body>` in _Layout.cshtml. However, it works if I render it in the `<head>` tag. Why is it ? Any help would be greatly appreciated - thanks

**BundlesConfig**

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


**布局**


**Layout**

      @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryIntellisense")
    @Scripts.Render("~/bundles/modernizr")
    @RenderSection("scripts", required: false)
</body>
</html>
     **View**
<script>
    $(document).ready(function () { alert("hello"); });
</script>

推荐答案

(document).ready(function(){alert("hello");}); </script>
(document).ready(function () { alert("hello"); }); </script>


Scripts.Render正在异步加载JavaScript脚本,因此无法预测jQuery是首先加载还是第二次或最后一次加载.
solutin将返回到加载脚本的旧"方式:

< script type ="text/javascript" src ="../Scripts/jquery-1.8.2.min.js"></script>

尽管这不是一个很好的解决方案,但您至少必须以此方式手动更新脚本的版本.
The Scripts.Render is loading the JavaScript scripts async, so there is no way to predict if jQuery is loading first or second or last.
The solutin is to go back to the "old" way of loading the scripts:

<script type="text/javascript" src="../Scripts/jquery-1.8.2.min.js"></script>

Although it is not an elegant solution and you have to manualy update the version of the script at least this way it works.


这篇关于jQuery-vsdoc无法使用MVC4捆绑吗?和@ Scripts.Render在上面的_Layout.cshtml中包含时不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆