网站发布到服务器时,jqGrid无法加载数据 [英] jqGrid not loading data when site published to server

查看:46
本文介绍了网站发布到服务器时,jqGrid无法加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的jqGrid有问题.我在这里看到了其他类似问题的帖子,除了我的特别之处在于,数据在我的开发机器中正确加载,但是当我在生产服务器上发布站点时,jqGrid不会加载数据,我得到的只是一个空的网格.除jqGrid之外,服务器中所有其他对数据的ajax请求都可以正常工作.我的项目在MVC3中,并且将站点托管在win2008 IIS7中.这是我当前的代码:

I have a problem with my jqGrid. I have seen other posts here with similar problem, except that mine is particular in that the data is loading correctly in my development machine but when I publish the site on my production server, the jqGrid won't load the data, all I get is an empty grid. Every other ajax request for data in the server works fine, except for the jqGrid. My project is in MVC3 and I am hosting the site in win2008 IIS7. This is my current code:

查看:

<script type="text/javascript">
$(document).ready(function () {
    $("#grid").jqGrid({
        url: '@Url.Action("LoadAction", "Controller", new { area = "Area" })',
        editurl: '@Url.Action("SaveAction", "Controller", new { area = "Area" })',
        datatype: 'json',
        mtype: 'POST',
        colNames: [
            '@Html.LabelFor(v => new foo.bar.MyClass().Property1)',
            '@Html.LabelFor(v => new foo.bar.MyClass().Property2)',
            '@Html.LabelFor(v => new foo.bar.MyClass().Property3)',
            '@Html.LabelFor(v => new foo.bar.MyClass().Property4)'
        ], 
        colModel: [
            { name: 'Property1', index: 'Property1', editable: true },
            { name: 'Property2', index: 'Property2', editable: true, edittype: "select", editoptions: { value: "Option1:Option1;Option2:Option2"} },
            { name: 'Property3', index: 'Property3', editable: true },
            { name: 'Property4', index: 'Property4', editable: true }
        ],
        pager: $('#gridPager'),
        rowNum: 20,
        rowList: [10, 20, 50, 100],
        sortname: 'Property1',
        sortorder: "asc",
        viewrecords: true,
        imgpath: '',
        shrinkToFit: true,
        width: 940,
        height: 300,
        gridview: true
    });
});
</script>
<div>
    <table id="grid" class="scroll" cellpadding="0" cellspacing="0"></table>
    <div id="gridPager" class="scroll" style="text-align:center;"></div>
</div>

控制器:

[Authorize]
public JsonResult LoadAction(string sidx, string sord, int page, int rows)
{
    List<foo.bar.MyClass> list = foo.bar.MyClassController.getAll();

    int pageIndex = Convert.ToInt32(page) - 1;
    int pageSize = rows;
    int totalRecords = list.Count();
    int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

    var jsonData = new
    {
        total = totalPages,
        page,
        records = totalRecords,
        rows = (
            from myclass in list
            select new
            {
                id = myclass.Id,
                cell = new string[] { 
                    myclass.Property1, 
                    myclass.Property2, 
                    myclass.Property3, 
                    myclass.Property4
                }
            }).ToArray()
    };
    return Json(jsonData);
}

任何人都不知道可能是什么问题吗?

Anyone have any idea what might be the problem?

谢谢.

推荐答案

1)我建议您在jqGrid定义中包括loadError事件处理程序.通过这种方式,您将看到来自服务器的错误响应.请参见答案<的更新部分.您可以从此处加载相应的演示项目.

1) I recommend you to include loadError event handler in your jqGrid definition. In the way you will see the error responses from the server. See the UPDATED part of the answer. You can load the corresponding demo project from here.

2)您应该验证发布站点的虚拟目录的配置.您使用[Authorize]属性.因此,应明确禁用匿名身份验证",并启用"Windows身份验证",表单身份验证"或您计划使用的其他身份验证.

2) You should verify the configuration of the virtual directory where you publish the site. You use [Authorize] attribute. So should disable "Anonymous Authentication" explicitly and enable "Windows Authentication", "Form Authentication" or other Authentication which you plan to use.

这篇关于网站发布到服务器时,jqGrid无法加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆