2014-02-16 79 views
0

我知道这个主题有很多线程。搜索了很多已经好几天了(!)......因此而变得疯狂。 我检查了这些: Uncaught TypeError: Object #<Object> has no method 'dialog' Uncaught TypeError: Object [object Object] has no method 'dialog'Uncaught TypeError:Object [object Object] has no method'dialog'

不能明白我做错了,需要你的帮助。下面是我正在努力工作的代码。

Index.chtml

@{ 
    ViewBag.Title = "Home Page"; 
} 

<br/> 
<input type="button" value="Get Form" onclick="getForm()" /> 


<script type="text/javascript"> 
function getForm(){$('#dialog').dialog({ 
      autoOpen: true, 
      width: 400, 
      resizable: false, 
      title: 'My Table', 
      modal: true, 
      open: function(event, ui) { 

       $(this).load('@Url.Action("Index", "Home")'); 
      }, 
      buttons: { 
       "Close": function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 
}</script> 

<div id="dialog"></div> 

控制器

public ActionResult _dialog() 
    { 
     return View(); 
    } 

    public ActionResult Index() 
    { 
     return View(); 
    } 

_dialog.chtml

<h3>Partial View code</h3> 

_Layout.chtml

... 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<script src="~/Scripts/jquery-ui-1.10.4.min.js"></script> 
<link href="@Url.Content("~/Content/themes/base/jquery-ui.css")" rel="stylesheet" type="text/css" /> 
... 
+1

你错过了jQuery UI库的链接吗? –

+0

检查您的外部脚本是否已正确嵌入到呈现的HTML代码中,并且可以实际到达(不是404或类似的东西)。 – CBroe

+0

^是的,将链接(src)复制到jquery ui lib并粘贴到您的浏览器(带域名),你能看到它吗? –

回答

0

我想有jQuery和jQuery用户界面的版本,您正在使用之间一些不兼容。尝试使用jQuery 2.0.0:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script> 
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" /> 

可能有一些问题与jQuery UI 1.10.4和jQuery> 2.0.0如jQuery 2.1.0例子。

+0

对不起,同样的错误。如果我删除了“@ Scripts.Render(”〜/ bundles/jquery“)”这一行,那么javascript可以工作,但不是模态,内容显示在页面的中心。 –

+0

为什么你有'@ Scripts.Render(“〜/ bundles/jquery”)'行?这将再次包含jQuery。您应该决定是使用捆绑包还是包含外部脚本。如果你使用bundle,那么使用'@ Scripts.Render(“〜/ bundles/jquery”)'并且在它使用'@ Scripts.Render(“〜/ bundles/jqueryui”)''''''之后,部分脚本{..}“部分。并且摆脱所有的自定义脚本包含,比如''和''你有。 –

+0

ловипять!!!非常感谢你。删除所有包并工作。现在我明白我做错了什么。 –

相关问题