我有一个错误,说$("#dialog").dialog({
是未定义的,我在一个新的MVC项目中做了同样的事情,并且它工作了。但是,当我将相同的代码移动到另一个MVC项目时,我得到了这个错误。请帮帮忙。我已经添加了jquery UI脚本。但是我还是得到了同样的错误。
<!DOCTYPE html>
<html lang="en">
<head>
<link href="~/Content/jquery-ui.css" rel="stylesheet" />
<script type="text/javascript" src="/Scripts/jquery-1.10.2.min.js"></script>
<body>
<form class="form-horizontal" role="form">
.......
</form>
<div id="dialog" title="Create Album" style="overflow: hidden;"></div>
</body>
@section scripts{
<script type="text/javascript">
var InitialFacility = '@ViewBag.ID';
$(document).ready(function () {
$('#tabs a').click(function(e) {
e.preventDefault();
$(this).tab('show');
});
$("#dialog").dialog({
autoOpen: false,
width: 400,
resizable: false,
title: 'hi there',
modal: true,
open: function (event, ui) {
//Load the CreateAlbumPartial action which will return
// the partial view _CreateAlbumPartial
$(this).load('@Url.Action("GetRrfForm","FacilityAdd")');
},
buttons: {
"Close": function () {
$(this).dialog("close");
}
}
});
$('#modal-opener').click(function () {
$('#dialog').dialog('open');
});
});
</script>
}
<div id="dialog" title="Create Album" style="overflow: hidden;"></div>
发布于 2015-01-16 14:59:45
您似乎没有在您的HTML中包含jQuery UI。
您可以从jQuery UI网站下载它,并将其保存在the应用程序中,并将其包含在html中,如下所示:
<script src="/<script_path_here>/jquery-ui.min.js"></script>
或
使用Google CDN链接包括前面提到的here的jQuery UI
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
发布于 2015-01-16 16:01:37
通过使用
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
@Scripts.Render("~/bundles/jquery")
<script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
在_Layout中,我在对话框窗口中加载jqxdatatable时也遇到了问题。但那是因为我使用的是不同版本的jquery-ui。因此删除了第二个verion,只使用了jquery-ui-1.8.24.min.js
https://stackoverflow.com/questions/27978546
复制相似问题