我是mvc的新手。我必须显示一个模态对话框..但它显示如下错误..代码应显示在下面..
在视图中
<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>
控制器中的
//[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());
}
答案 0 :(得分:5)
您需要添加以下对页面的引用
<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>
的更新强> 的
在你的评论中,你完全错了。使您的代码如下,并删除其他引用。
BundleConfig,
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
布局,
@Styles.Render("~/Content/themes/base/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryui")
答案 1 :(得分:2)
看起来对话框DIV的ID不匹配。
尝试将JS更改为:
$('#dialog-modal').dialog({