首页 新闻 会员 周边

easyui datagrid报错“对象不支持‘datagrid’属性或方法”

0
悬赏园豆:15 [已解决问题] 解决于 2013-05-24 17:58

新建一个asp.net的MVC项目,在.cshtml文件中添加datagrid插件,代码片段如下所示:

<table id="dg" class="easyui-datagrid" title="DataGrid Complex Toolbar" style="width: 700px; height: 250px"
    data-options="rownumbers:true,singleSelect:true,fitColumns:'true',pagination:'true',url:'/Student/GetStudentInformation',toolbar:'#toolbar'">
    <thead>
        <tr>
            <th data-options="field:'StudentName',width:80">StudentName</th>
            <th data-options="field:'StudentNumber',width:100">StudentNumber</th>
            <th data-options="field:'Department',width:80,align:'right'">Department</th>
            <th data-options="field:'Birthday',width:80,align:'right'">Birthday</th>
        </tr>
    </thead>
</table>

在.cshtml文件的代码中有一个按钮,点击这个按钮会调用destroyStudent函数,删除选中的一行数据。destroyStudent函数的代码如下所示:

<head>
    <script type="text/javascript" src="~/Scripts/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="~/Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript">

    function destroyStudent() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('Confirm', 'Are you sure you want to destroy this user?', function (r) {
                if (r) {
                    $.ajax({
                        dataType: 'json',
                        type: 'POST',
                        url: '@Url.Content("~/Student/DeleteStudentInformation")',
                        data: "StudentId=" + row.StudentId,
                        success: function (data, status, xhr) {
                            $('#dg').datagrid('reload');
                        },
                        error: function (jqXHR, textStatus, errorThrown) {
                            alert('删除数据失败');
                            //commit(false);
                        }
                     });
                }
            });
        }
    }
    </script>
</head>

 运行之后能够从数据库中获取数据显示在datagrid表格中,但是当点击“删除”按钮调用“destroyStudent”函数时,第8行一直报错“对象不支持‘datagrid’属性或方法”,这是为什么呢?谢谢。

sikla的主页 sikla | 初学一级 | 园豆:27
提问于:2013-05-20 17:32
< >
分享
最佳答案
0

  第一次是基于“基本”模板新建的MVC4应用程序,后来新建了一个“空白”模板的MVC应用程序,再把代码复制进去,就没报错了。

  我观察过使用“基本”模板与使用“空白”模板新建的项目中页面之间的差别,发现两者的html代码不同,前者的代码自动添加了外层的html元素,引入了一些js和css文件,而后者没有。

sikla | 初学一级 |园豆:27 | 2013-05-24 17:56
其他回答(3)
0
 <script type="text/javascript" src="~/Scripts/jquery.datagrid.js"></script>  这个可以去掉
收获园豆:5
@@@一统@@@ | 园豆:1551 (小虾三级) | 2013-05-20 20:25

把这条引用注释掉也还是报同样的错误啊,求指教。

支持(0) 反对(0) sikla | 园豆:27 (初学一级) | 2013-05-21 09:50
0

你检查下 min.js的路径  还不行 重新下载个easyui压缩包吧

收获园豆:5
yesyes | 园豆:9 (初学一级) | 2013-05-21 11:30
0

<tr>
            <th data-options="field:'StudentName',width:80">StudentName</th>
            <th data-options="field:'StudentNumber',width:100">StudentNumber</th>
            <th data-options="field:'Department',width:80,align:'right'">Department</th>
            <th data-options="field:'Birthday',width:80,align:'right'">Birthday</th>
        </tr>

grid里没有这个"StudentId“字段。

收获园豆:5
数据酷软件 | 园豆:130 (初学一级) | 2013-05-21 18:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册