对象不支持属性或方法“对话框” [英] Object doesn't support property or method 'dialog'

查看:773
本文介绍了对象不支持属性或方法“对话框”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为参照链接,我创建从一个MVC UI对话框。

这是我的code:

在Layout.cshtml

Refering the Link, I created a UI dialog from MVC.
Here is my code:
In Layout.cshtml

  <head>
        <meta charset="utf-8" />
        <title>@ViewBag.Title - My ASP.NET MVC Application</title>
        <link href="../../Content/smoothness/jquery-ui-1.10.2.custom.css" rel="stylesheet"  type="text/css" />
        <script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
        <script src="../../Scripts/jquery-ui-1.10.2.custom.min.js" type="text/javascript"></script>
        <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <meta name="viewport" content="width=device-width" />
        @Styles.Render("~/Content/css")
        @Scripts.Render("~/bundles/modernizr")
    </head>

Index.cshtml

   <h2>jQuery UI Hello World</h2>          
    <button id="show-dialog">Click to see jQuery UI in Action</button>            
    <div id="dialog" title="jQuery UI in ASP.NET MVC" >  
       <p>You now have the power of ASP.NET, the simplicity of client-side scripting with jQuery, and the looks of jQuery UI.  Congrats, web slinger!</p>  
    </div>    
    <script language="javascript" type="text/javascript">
        $(function () {
            $('#dialog').dialog({
                autoOpen: false,
                width: 600,
                buttons: {
                    "Ok": function () { $(this).dialog("close"); },
                    "Cancel": function () { $(this).dialog("close"); }
                }
            });
            $("#show-dialog").button().click(function () {
                $('#dialog').dialog('open');
                return false;
            });
        });  
    </script>    

我在IE和Firefox这两种检查。火狐抛出的类型错误$(...)。对话框是不是一个函数并抛出IE浏览器的对象不支持属性或方法对话框
任何建议。什么是我的code中的错误。为什么会出现对话框错误??

I checked both in IE and Firefox. Firefox throws "Typeerror $(...).dialog is not a function" and IE throws Object doesn't support property or method 'dialog'.
Any suggestions. What is the mistake in my code. Why dialog error occurs ??

推荐答案

3的事情浮现在脑海中,可能是值得一试:

3 things come to mind that might be worth checking:


  1. 在ASP.NET MVC应用程序决不要硬code的URL。始终使用(这是推荐或包)助手:

  1. Never hardcode urls in an ASP.NET MVC application. Always use helpers (or bundles which are recommended):

<head>
    <meta charset="utf-8" />
    <title>@ViewBag.Title - My ASP.NET MVC Application</title>
    <link href="~/Content/smoothness/jquery-ui-1.10.2.custom.css" rel="stylesheet"  type="text/css" />
    <script src="~/Scripts/jquery-1.9.1.js" type="text/javascript"></script>
    <script src="~/Scripts/jquery-ui-1.10.2.custom.min.js" type="text/javascript"></script>
    <link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <meta name="viewport" content="width=device-width" />
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>


  • 确认,在年底你的 _Layout.cshtml 你没有一个 @ Scripts.Render(〜/包/ jQuery的)调用,因为这将包括jQuery的两倍。

  • Make sure that at the end of your _Layout.cshtml you don't have a @Scripts.Render("~/bundles/jquery") call because this would include jQuery twice.

    如果你的 _Layout.cshtml 你有像 @RenderSection自定义脚本专用的部分(脚本末,必需:false),请确保您已放置在您的自定义脚本在这一节中(请注意,因为这是RenderSection在DOM结束时,你并不需要被包装脚本的文件中。就绪事件,因为由它执行的时间,则DOM将已经加载):

    If at the end of your _Layout.cshtml you have a dedicated section for custom scripts like @RenderSection("scripts", required: false), make sure that you have placed your custom script in that section (notice that since this RenderSection is at the end of the DOM you don't need to be wrapping your script in a document.ready event because by the time it executes, the DOM will already be loaded):

    <h2>jQuery UI Hello World</h2>          
    <button id="show-dialog">Click to see jQuery UI in Action</button>            
    <div id="dialog" title="jQuery UI in ASP.NET MVC" >  
       <p>You now have the power of ASP.NET, the simplicity of client-side scripting with jQuery, and the looks of jQuery UI. Congrats, web slinger!</p>  
    </div>    
    
    @section scripts {
        <script type="text/javascript">
            $('#dialog').dialog({
                autoOpen: false,
                width: 600,
                buttons: {
                    "Ok": function () { $(this).dialog("close"); },
                    "Cancel": function () { $(this).dialog("close"); }
                }
            });
            $("#show-dialog").button().click(function () {
                $('#dialog').dialog('open');
                return false;
            });
        });  
        </script>
    }
    


  • 这篇关于对象不支持属性或方法“对话框”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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