2

好的,所以我第一次尝试 jTable,我可以加载表,但这对我没有什么好处,因为它不会加载我的任何数据。当我调试程序时,我想要的表中的所有行都存储在我的列表中,所以我很困惑为什么当我运行我的应用程序时会弹出一个对话框说“与服务器通信时发生错误” :

[HttpPost]
public JsonResult General_InfoList(int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
{
    try
    {
        // When debugging, all rows are successfully being stored in this list
        // but a dialog box pops up saying 'An error occured while communicating to the server.'
        Thread.Sleep(200);
        var genInfoCount = _repository.General_Info_Repository.GetGeneral_InfoCount();
        var genInfo = _repository.General_Info_Repository.GetGeneral_Info(jtStartIndex, jtPageSize, jtSorting);
        return Json(new { Result = "OK", Records = genInfo, TotalRecordCount = genInfoCount });

    }
    catch (Exception ex)
    {
        return Json(new { Result = "ERROR", Message = ex.Message });
     }
}

在我看来,我有:

<div id="General_InfoTableContainer">
</div>
<script type="text/javascript">

    $(document).ready(function () {

        $('#General_InfoTableContainer').jtable({
            title: 'General_Info List',
            paging: true,
            pageSize: 10,
            sorting: true,
            defaultSorting: 'Quote ID ASC',
            actions: {
                listAction: '@Url.Action("General_InfoList")',
                deleteAction: '@Url.Action("DeleteGeneral_Info")',
                updateAction: '@Url.Action("UpdateGeneral_Info")',
                createAction: '@Url.Action("CreateGeneral_Info")'
            },
            fields: {
                QuoteID: {
                    key: true,
                    create: false,
                    edit: false,
                    list: true,
                    title: 'ID',
                    width: '5%'
                },
                Open_Quote: {
                    title: 'Open Quote',
                    list: true,
                    width: '15%',
                    type: 'date',
                    displayFormat: 'mm-dd-yy'
                },
                Customer_Name: {
                    list: true,
                    title: 'Customer',
                    width: '25%'
                },
                OEM_Name: {
                    title: 'OEM',
                    list: true,
                    width: '25%'
                },
                Qty: {
                    title: 'Qty',
                    list: true,
                    width: '5%'
                },
                FD_Num: {
                    title: 'FD Num',
                    width: '10%',
                    list: true,
                    sorting: false
                },
                Rfq_Num: {
                    title: 'RFQ',
                    width: '10%',
                    list: true,
                    sorting: false
                },
                Rev_Num: {
                    title: 'Rev',
                    width: '5%',
                    list: true,
                    sorting: false
                },

                Score_Card: {
                    create: false,
                    edit: false,
                    list: false
                },
                Quantities: {
                    create: false,
                    edit: false,
                    list: false
                },
                QuoteAccesses: {
                    create: false,
                    edit: false,
                    list: false
                },
                Vendor_Input: {
                    create: false,
                    edit: false,
                    list: false
                }              
            }
        });

        //Load student list from server
        $('#General_InfoTableContainer').jtable('load');
    });

</script>

如果有人在我上面的代码中看到任何会阻止数据加载的内容,请告诉我。 - 谢谢

4

1 回答 1

3

你的陈述中缺少JsonRequestBehaviour.AllowGet你。return Json(...)看起来它是可选的,但我发现实际上它是必需的。

return Json(new { Result = "OK", Records = genInfo }, JsonRequestBehaviour.AllowGet);

额外提示:当您从 ajax 调用中获得神秘的 500 时,请在 Visual Studio 中执行以下操作:

  1. 调试菜单->异常...
  2. 选择“通用语言运行时异常”。

这将强制您的服务器代码在/如果发生异常时停止。当然,它也可能向您显示误报,因此您可能希望在打开此功能时有所选择。

于 2013-05-24T20:51:35.873 回答