无法获取要加载到MVC 4中的jTable中的数据 [英] Can't get data to load into jTable in mvc 4

查看:111
本文介绍了无法获取要加载到MVC 4中的jTable中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Okay, so I'm trying out jTable for the first time and I can get the table to load, but that does me very little good because it won't load with any of my data. When I debug the program, all of the rows from the table I want are getting stored in my List so I'm confused as to why a dialog box pops up when I run my application saying 'An error occured while communicating to the server':

[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>

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

If anyone sees anything in my code above that would prevent the data from loading please let me know. --Thanks

推荐答案

您在return Json(...)语句中缺少JsonRequestBehaviour.AllowGet.看来它是可选的,但实际上我发现它是必需的.

You are missing JsonRequestBehaviour.AllowGet from your return Json(...) statement. It seems that it's optional, but I find in reality it's required.

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

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

Bonus Hint: when you get mysterious 500's from your ajax calls, do the following inside Visual Studio:

  1. 调试菜单->异常...
  2. 选择公共语言运行时例外".

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

This will force your server code to stop when/if an exception occurs. Of course, it can also show you false positives, so you may want to be selective on when you turn this on.

这篇关于无法获取要加载到MVC 4中的jTable中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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