jQuery JavaScript 运行时错误:对象不支持 MVC4 中的属性或方法“对话框”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17058190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript runtime error: Object doesn't support property or method 'dialog' IN MVC4
提问by Souparnika
I'm new in mvc. I have to display a model dialog box.. but it shows an error like this.. the code should be shown below..
我是 mvc 新手。我必须显示一个模型对话框..但它显示了这样的错误..代码应该显示在下面..
in view
鉴于
<div class="demo">
<div id="dialog-modal" title="Basic dialog">
</div>
<button id="opener">Open Dialog</button>
</div>
<script type="text/javascript">
$(function () {
$('#dialog').dialog({
autoOpen: false,
width: 400,
resizable: false,
title: 'hi there',
modal: true,
buttons: {
"Close": function () {
$(this).dialog("close");
}
}
});
$('#opener').click(function () {
//Load the CreateAlbumPartial action which will return
// the partial view _CreateAlbumPartial
$('#dialog').load('@Url.Action("PartialTest")',
function (response, status, xhr) {
$('#dialog').dialog('open');
});
});
});
</script>
in controller
在控制器中
//[HttpGet]
public PartialViewResult Test()
{
//List<string> category_lst = new List<string>();
//category_lst = (from r in db.dept select r.dname).ToList();
return PartialView(db.dept.ToList());
}
回答by Chamika Sandamal
You need to add following references to the page
您需要在页面中添加以下引用
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
Update
更新
In your comment, you are doing it totally wrong. Make your code like following and remove other references.
在您的评论中,您完全错了。使您的代码如下所示并删除其他引用。
BundleConfig,
捆绑配置,
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
Layout,
布局,
@Styles.Render("~/Content/themes/base/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
回答by Kevin Hinshaw
It looks like there's a mismatch in your IDs for the dialog DIV.
对话框 DIV 的 ID 似乎不匹配。
- the HTML uses "dialog-modal"
- the JS uses "dialog"
- HTML 使用“对话框模式”
- JS 使用“对话框”
Try changing the JS to this:
尝试将 JS 更改为:
$('#dialog-modal').dialog({