【发布时间】:2021-04-19 19:47:38
【问题描述】:
所以决定更新我项目中的一些包,但总是有问题。我有一个设置,其中一个链接会弹出一个带有.chtml 文件的模态对话框。我使用了一个名为 ModalDialogExtentions 的助手,它调用了一个名为 modaldialog.js 的 Javascript 文件。当我更新 JQuery 和 Bootstrap 时,虽然我不相信更新 bootstrap 与它有任何关系,但我的模态显示在页面底部 - 就像卡住一样。
我在控制台窗口中收到一条错误消息,上面写着modaldialog.js:30 Uncaught TypeError: div.dialog is not a function,这让我想到了这一点:
function openModalDialog(dialogDivId, title) {
var div = $("#" + dialogDivId);
div.dialog({
title: title,
close: new Function("clearModalDialog('" + dialogDivId + "');"),
modal: true,
width: "auto",
height: "auto",
resizable: true
});
setFormDataAjaxAttributes(dialogDivId);
}
有谁知道这个版本的 JQuery 发生了什么变化?原始版本是 1.10.2。我知道我已经将它更新为 3.x.x 并且运行良好。但这个版本没有。它还在控制台中提到了这个文件以及JQuery.unobtrusive-ajax.js。我也更新了这个。
完整的控制台错误:
modaldialog.js:30 Uncaught TypeError: div.dialog is not a function
at openModalDialog (modaldialog.js:30)
at HTMLAnchorElement.eval (eval at getFunction (jquery.unobtrusive-ajax.js:34), <anonymous>:3:1)
at Object.success (jquery.unobtrusive-ajax.js:105)
at c (jquery-3.5.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.5.1.min.js:2)
at l (jquery-3.5.1.min.js:2)
at XMLHttpRequest.<anonymous> (jquery-3.5.1.min.js:2)
感谢您的帮助!
更新:
这是模态对话框扩展之一:
public static MvcHtmlString ModalDialogActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string dialogTitle, string CssClass)
{
var dialogDivId = Guid.NewGuid().ToString();
return ajaxHelper.ActionLink(linkText, actionName, routeValues: null,
ajaxOptions: new AjaxOptions
{
UpdateTargetId = dialogDivId,
InsertionMode = InsertionMode.Replace,
HttpMethod = "GET",
OnBegin = string.Format(CultureInfo.InvariantCulture, "prepareModalDialog('{0}')", dialogDivId),
OnFailure = string.Format(CultureInfo.InvariantCulture, "clearModalDialog('{0}');alert('You are not authorized to access this area!')", dialogDivId),
OnSuccess = string.Format(CultureInfo.InvariantCulture, "openModalDialog('{0}', '{1}')", dialogDivId, dialogTitle)
}, htmlAttributes: new { @class = CssClass });
}
【问题讨论】:
标签: javascript jquery jquery-plugins