从IIS 7.2(虚拟目录)运行时jqGrid不起作用

时间:2011-07-01 10:09:27

标签: asp.net-mvc-3

专家,

我已经创建了一个应用程序,并为添加,编辑和删除实现了JQGrid,从Visual Studio 2010运行时运行正常。

现在我为这个应用程序创建了虚拟目录,然后我尝试访问索引页面它不会显示任何内容,因为JQGrid没有加载它给了我  以下错误: 错误:jQuery(“#list”)。jqGrid不是函数 源文件:http://localhost/CAFM/TabMaster 行:58

以下是JQGrid代码段。

jQuery(document).ready(function () {
        alert(jQuery("#list"));
        jQuery("#list").jqGrid({
            url: '/TabMaster/JQGridGetGridData',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['col ID', 'First Name', 'Last Name'],
            colModel: [
                      { name: 'colID', index: 'colID', width: 100, align: 'left', searchoptions: { sopt: ['eq', 'ne', 'cn']} },
                      { name: 'FirstName', index: 'FirstName', width: 150, align: 'left', editable: true },
                      { name: 'LastName', index: 'LastName', width: 300, align: 'left', editable: true },
                    ],
            pager: jQuery('#pager'),
            rowNum: 100,
            rowList: [10, 50, 100, 500, 1000, 2000, 5000, 7000, 10000],
            sortname: 'colID',
            sortorder: "asc",
            viewrecords: true,
            multiselect: true,
            imgpath: '/scripts/themes/steel/images',
            caption: 'Tab Master Information'
        }).navGrid('#pager', { edit: true, add: true, del: true },
        // Edit options
                {
                savekey: [true, 13],
                reloadAfterSubmit: true,
                jqModal: false,
                closeOnEscape: true,
                closeAfterEdit: true,
                url: "/TabMaster/JQGridEdit",
                afterSubmit: function (response, postdata) {
                    if (response.responseText == "Success") {
                        jQuery("#success").show();
                        jQuery("#success").html("Record updated successfully! [" + postdata.FirstName + " " + postdata.LastName + "]");
                        jQuery("#success").fadeOut(6000);
                        return [true, response.responseText]
                    }
                    else {
                        return [false, response.responseText]
                    }
                }
            },
        // Add options
                {
                url: '/TabMaster/JQGridCreate',
                closeAfterAdd: true,
                afterSubmit: function (response, postdata) {
                    if (response.responseText == "Success") {
                        jQuery("#success").show();
                        jQuery("#success").html("Record added successfully! [" + postdata.FirstName + " " + postdata.LastName + "]");
                        jQuery("#success").fadeOut(6000);
                        return [true, response.responseText]
                    }
                    else {
                        return [false, response.responseText]
                    }
                }
            },
        // Delete options
               {
               url: '/TabMaster/JQGridRemove',
               afterSubmit: function (response, rowid) {
                   if (rowid.length > 0) {
                       jQuery("#success").show();
                       jQuery("#success").html("Record deleted successfully! [" + rowid + "]");
                       jQuery("#success").fadeOut(6000);
                       return [true, response.responseText]
                   }
                   else {
                       return [false, response.responseText]
                   }
               }
           },
                {
                    closeOnEscape: true,
                    multipleSearch: false,
                    closeAfterSearch: true
                }
                   );
    });

以下是我在项目中包含的JQuery文件。

 <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/modernizr-1.7.min.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/Content/themes/base/jquery.ui.theme.css")" rel="Stylesheet" type="text/css" />
    <link href="@Url.Content("~/Scripts/themes/steel/grid.css")" rel="Stylesheet" type="text/css" />
    <link href="@Url.Content("~/Scripts/themes/jqModal.css")" rel="Stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.jqGrid.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/js/jqModal.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/js/jqDnR.js")" type="text/javascript"></script>

以下是脚本的层次结构

enter image description here

提前致谢! Imdadhusen

1 个答案:

答案 0 :(得分:4)

它不起作用,因为您已经对您的网址进行了硬编码:

url: '/TabMaster/JQGridGetGridData'

在处理网址时,您应始终使用网址帮助:

url: '@Url.Action("JQGridGetGridData", "TabMaster")'

在虚拟目录中部署应用程序时,地址i不再是/TabMaster/JQGridGetGridData,而是/YourApplicationName/TabMaster/JQGridGetGridData。这就是你应该总是使用网址助手的原因。

您的编辑选项网址和图片路径也是如此。对于静态资源,请使用@Url.Content,对于控制器操作,请使用@Url.Action