微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

带有 jsGrid 的 ASPNETCORE 5.0loadData 问题

如何解决带有 jsGrid 的 ASPNETCORE 5.0loadData 问题

加载一些数据时jsgrid出现问题(加载数据失败)

这是我的代码

客户:

    <script>
    $(function() {

        $("#jsGrid").jsGrid({
            height: "50%",width: "100%",filtering: true,inserting: true,editing: true,sorting: true,paging: true,autoload: true,pageSize: 10,pageButtonCount: 5,deleteConfirm: "Do you really want to delete client?",controller: {
                loadData: function (filter) {
                    var d = $.Deferred();
                    $.ajax({
                        type: "POST",url: '@Url.Action("Category","Management")' + '?method=' + 'GET',data: filter,contentType: 'application/json; charset=utf-8',dataType: "json"
                    }).done(function (response) {
                        d.resolve(response.value);
                    });
                    return d.promise();
                }
                
            },fields: [
                { name: "Categoria",type: "text",width: 150 },{ name: "Id",type: "number",width: 50 },{ name: "Nome",{ name: "Valor",width: 200 },{ type: "control" }
            ]
        });

    });
    </script>

服务器:

[HttpPost]
public IActionResult Category(string method,[FromBody] Product filter)
{
    if(method.toupper() == "GET")
    {
        var aa = productRepository.GetProducts.ToList();
        return StatusCode(200,aa);
    }
    else
    {
        return null;
    }
}

这是我的调试结果 enter image description here

成功加载数据!但是,吹这个代码

d.resolve(response.value);

response.value 中存在非值......我如何添加或创建它?

http://js-grid.com/docs/

jsgrid主页说

loadData 是一个返回数据数组或 jQuery 承诺的函数,它将用数据数组解析(当 pageLoading 为 true 而不是对象时,结构 { data: [items],itemsCount: [total items count] } 应该被退回)。当 pageLoading 为 true 时,接受过滤器参数,包括当前过滤器选项和分页参数。

我不知道如何解决这个问题。

我想我在后端代码中遇到了一些问题

请帮帮我。

谢谢。

解决方法

试试

[HttpPost]
public IActionResult Category(string method,[FromBody] Product filter)
{
    if(method.ToUpper() == "GET")
    {
        var aa = productRepository.GetProducts.ToList();
        return Json(aa);
    }
    else
    {
        return null;
    }
}

在方法中。可能你没有返回一个 Json 对象。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。