Asp.Net Core MVC5中DevExpress dxDataGrid函数报错求助
解决$(...).dxDataGrid is not a function 异常
核心问题:脚本加载顺序错误
DevExtreme 的 dx.all.js 依赖 jQuery,必须先加载 jQuery,再加载 DevExtreme 脚本。你当前的代码把 dx.all.js 放在 jQuery 之前加载,导致 DevExtreme 无法绑定到 jQuery 对象上,自然找不到 dxDataGrid 方法。
修正后的头部脚本顺序:
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/23.1.3/css/dx.common.css" /> <link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/23.1.3/css/dx.light.css" /> <!-- 先加载 jQuery --> <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <!-- 再加载 DevExtreme 脚本 --> <script src="https://cdn3.devexpress.com/jslib/23.1.3/js/dx.all.js" type="text/javascript"></script>
其他排查方向
如果修正顺序后仍报错,检查以下几点:
- 重复加载 jQuery:查看你的 MVC 布局页(如
_Layout.cshtml)是否已经加载了 jQuery,若页面中再次加载会导致全局 jQuery 对象被覆盖,DevExtreme 绑定的旧对象失效。 - 版本兼容性:确认 jQuery 版本与 DevExtreme 版本兼容(你当前用的 jQuery 3.5.1 和 DevExtreme 23.1.3 是兼容的,但如果后续升级版本需核对官方兼容列表)。
- 捆绑配置问题:如果项目使用了
BundleConfig,需确保 jQuery 捆绑包在 DevExtreme 捆绑包之前引入。 - CDN 加载失败:打开浏览器控制台的「Network」标签,检查
dx.all.js和 jQuery 是否成功加载(无 404 或加载超时)。 - 脚本执行时机:确保初始化代码在 DOM 加载完成后执行,你当前用
$(() => {})是正确的,但如果脚本被放在<head>标签内且未包裹 DOM 就绪事件,也会导致找不到 DOM 元素。
内容的提问来源于stack exchange,提问作者omercan
相关产品推荐
相关产品推荐

