简体   繁体   English

telerik asp.net核心网格不显示返回的数据

[英]telerik asp.net core grid not displaying returned data

This should be a easy solution, but I have been beating on it for 2 hours. 这应该是一个简单的解决方案,但我已经对其进行了2个小时的殴打。

I have a telerik grid defined here: 我在这里定义了telerik网格:

  @(Html.Kendo().Grid<Models.LOB.RebateAssignedUpc>
                        ().Name("gridCustomers")
                        .Columns(c =>
                        {
                            c.Bound(e => e.Id).Title("Id");
                            c.Bound(e => e.Upc).Title("UPC");

                        })
                        .Groupable()
                  .DataSource(source =>
                  {
                      source.Custom()
                      .Transport(transport =>
                      {
                          transport.Read("GetUPCs", "Upc2");
                      });

                  })
    )  

It is calling this method in the controller, which I have verified is called and is getting data: 它在控制器中调用此方法,我已验证该方法已被调用并正在获取数据:

public ActionResult GetUPCs()
    {
        List<RebateAssignedUpc> upcDetails = db.RebateAssignedUpc.ToList();

        var result = db.RebateAssignedUpc.Select(x => new
        {
           x.Id,
           x.Upc
        }).ToList();

        var output = JsonConvert.SerializeObject(result);

        return Json(output);

    }

the grid displays but with no data, it does have the columns and the group by section is showing. 网格显示,但没有数据,它确实具有列,并且显示了按节分组。 Using a breakpoint in the controller the output is showing: 在控制器中使用断点,输出显示:

"[{\\"Id\\":1,\\"Upc\\":\\"12345\\"},{\\"Id\\":2,\\"Upc\\":\\"12346\\"},{\\"Id\\":5,\\"Upc\\":\\"12345\\"}]" “ [{\\” Id \\“:1,\\” Upc \\“:\\” 12345 \\“},{\\” Id \\“:2,\\” Upc \\“:\\” 12346 \\“},{\\” Id \\“:5,\\” Upc \\“:\\” 12345 \\“}]”

Using f12 I verified that the controller is returning this data to the browser: 使用f12,我验证了控制器正在将此数据返回到浏览器:

"[{\\"Id\\":1,\\"Upc\\":\\"12345\\"},{\\"Id\\":2,\\"Upc\\":\\"12346\\"},{\\"Id\\":5,\\"Upc\\":\\"12345\\"}]" “ [{\\” Id \\“:1,\\” Upc \\“:\\” 12345 \\“},{\\” Id \\“:2,\\” Upc \\“:\\” 12346 \\“},{\\” Id \\“:5,\\” Upc \\“:\\” 12345 \\“}]”

I tried manually doing it this way as well: 我也尝试通过这种方式手动执行此操作:

 List<RebateAssignedUpc> upc = new List<RebateAssignedUpc>{
               new RebateAssignedUpc{Id = 1, Upc = "1234"}

               };

        string jsonString = JsonConvert.SerializeObject(upc);

        return Json(jsonString);

I defined the grid wrong in the beginning and I also needed to provide Schema data. 我在一开始就定义了错误的网格,我还需要提供Schema数据。

  @(Html.Kendo().Grid<WebPortal.Controllers.upcReturnData>().Name("gridCustomers")
                                                 .Columns(
                                    c =>
                                    {
                                        c.Bound(e => e.upc).Title("UPC");

                                    })
                                    .Scrollable()
                                    .Resizable(resize => resize.Columns(true))
                                    .DataSource(source =>
                                    {
                                        source.Custom()
                                        .Transport(transport =>
                                        {
                                            transport.Read("GetUPCs", "upc2");
                                        }).Schema(schema =>
                                        {
                                            schema.Data("dataReturned");

                                        });
                                    })

The controller and the partial class of upcReturnedData used in defining the grid: 定义网格时使用的控制器和upcReturnedData的子类:

 public ActionResult GetUPCs()
        {
           // List<upcReturnData> upcDetails = db.RebateAssignedUpc.ToList();

            var result = db.RebateAssignedUpc.Select(x => new
            {
               id= x.Id,
               upc=x.Upc

            }).ToList();


            return Json( new { dataReturned = result });

        }
public partial class upcReturnData
{
    public int id { get; set; }
    public string upc { get; set; }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM