MVC 5使用@ Scripts.Render(QUOT;〜/包/ jQuery和QUOT;)和JQuery对话框 [英] MVC 5 with @Scripts.Render("~/bundles/jquery") and JQuery Dialog

查看:209
本文介绍了MVC 5使用@ Scripts.Render(QUOT;〜/包/ jQuery和QUOT;)和JQuery对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始工作的MVC。今天,我试着写一个测试应用程序只是为了显示一个jQuery的对话框,每当我点击一个按钮。我在Visual Studio 2013中选择MVC模板创建一个Web项目。在Index.cshtml我有以下code。我包括所有的UI从jqueryui.com

I have just started working on MVC. Today I tried writing a test application just to show a Jquery Dialog whenever I click on a button. I created a web project in Visual Studio 2013 and selected MVC template. in Index.cshtml I have following code. I included all the ui related js files from downloading from jqueryui.com

@{
ViewBag.Title = "Home Page";
}
<link href="~/Scripts/jquery-ui.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery-ui.js"></script>
<div id="dialog" title="Basic dialog">
<p> This is a basic dialog.</p>
</div>
<button type="button" id="open">Click Me.</button>
<script type="text/javascript">
    $(document).ready(function () {
    $("#open").click(function () {
        $("#dialog").dialog();
    });
});
</script>

当我尝试了c那么它根本不工作超过$ C $运行。但是,当我在_Layout.cshtml注释以下行它的工作。

When I tried to run above code it didn't worked at all. But when I commented following line in _Layout.cshtml it worked.

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

我试着在注释文件Index.cshtml的包括脚本部分没有上面的行注释,但没有奏效。当我上面一行注释的对话框只显示。

I tried commenting the include script section in Index.cshtml file without commenting above line but it didn't worked. The dialog only shows when I comment above line.

谁能告诉我什么是这里的问题还是资源在那里我能得到这个问题的详细信息的任何链接?

Can anybody tell me what is the issue here or any link to the resource where I can get more information about this issue?

推荐答案

不包括 JS / CSS 上查看文件,只要它的软件包(我认为JS / css文件是否有bundleconfig,你也明确地包括他们认为,这就是为什么他们js文件相互矛盾)只是渲染布局页面上捆绑@ Scripts.Render(〜/包/ jQuery的 ),然后使用下面code对你的看法: -

Don't include js/css file on view,just make its bundle(i think js/css files are there in bundleconfig and you are also explicitely including them in view and that is why they js files are conflicting) just render bundles on Layout page with @Scripts.Render("~/bundles/jquery") and then use below code on your view :-

使用 @section脚本{} 在.cshtml为: -

Use @section scripts{ } in .cshtml as :-

 @section scripts{
   <script type="text/javascript">
    $(document).ready(function () {
      $("#open").click(function () {
       $("#dialog").dialog();
     });
   });
   </script>
 }

这篇关于MVC 5使用@ Scripts.Render(QUOT;〜/包/ jQuery和QUOT;)和JQuery对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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