简体   繁体   English

Kendo UI网格未显示数据

[英]Kendo UI grid is not showing data

I am using MVC Kendo grid and unable to populate the grid. 我正在使用MVC Kendo网格,但无法填充网格。 Here is the cshtml code 这是cshtml代码

@(Html.Kendo().Grid<EntryPointCRR.Models.GuarantorInfo>()
        .Name("kgGuarantor")
        .Columns(c =>
        {
            //  c.Bound(p => p.Id);
            c.Bound(p => p.Rank);
            c.Bound(p => p.GuarantorNameModel.Name);
            c.Bound(p => p.GuarantorNameModel.CisNumber);
            c.Bound(p => p.Type);
            c.Bound(p => p.GuaranteeShare);
            c.Template(@<text></text>).ClientTemplate(@"<a class=""k-button k-button-icontext k-grid-edit"" href=""\#""><span class=""fa fa-pencil""></span></a><a class=""k-button-icontext k-grid-delete"" href=""\#""><span class=""fa fa-trash-o""></span></a>");
        })
             .ToolBar(toolBar =>
             {
                 toolBar.Create().Text("Add Guarantor");
             })
            .Editable(editable => editable.Mode(GridEditMode.PopUp))
            .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
            .DataSource(dataSource => dataSource.Ajax()
                        .ServerOperation(false)
                        .Model(model => model.Id(p => p.Id))
                        .Create(create => create.Action("AddGuarantors", "Guarantor"))
                                            .Read(read => read.Action("GetGuarantorSummary", "Guarantor", new { packageId = 1, packageProductId = 1 }))

            )
        )

and here is the my controller code 这是我的控制器代码

public ActionResult GetGuarantorSummary(string packageId, string packageProductId)
        {
            GuarantorModel objGuarantorModel = new GuarantorModel();
            try
            {
                //Guarantors objGuarantors = new Guarantors(packageId, packageProductId);
               // objGuarantorModel = objGuarantors.GetGuarantorsSummary();
                objGuarantorModel = GetGuarantorsStubbedData();
            }
            catch (Exception ex)
            {
                Logger.Write(ex, "General", 1, 1, System.Diagnostics.TraceEventType.Error);
            }
            return View("Guarantor", objGuarantorModel);
        }

  private GuarantorModel GetGuarantorsStubbedData()
        {
            GuarantorModel objGuarantorModel = new GuarantorModel();
            objGuarantorModel.GuarantorDetails.Add(new GuarantorInfo
            {
                Id = 1,
                Rank = "1",
                Type = "Full",
                GuaranteeShare = "30%",
                GuarantorNameModel = new GuarantorNameModel
                {
                    Name = "Acme",
                    CisNumber = "12345"
                }
            });
            objGuarantorModel.GuarantorDetails.Add(new GuarantorInfo
            {
                Id = 2,
                Rank = "3",
                Type = "Full",
                GuaranteeShare = "40%",
                GuarantorNameModel = new GuarantorNameModel
                {
                    Name = "Acme Company",
                    CisNumber = "123456"
                }
            });

            return objGuarantorModel;
        }

I can see only the grid header not the data. 我只能看到网格标题,而不能看到数据。 Can you please hep me to sort out this issue? 您能帮我解决这个问题吗?

You need to change your "GetGuarantorSummary" action result as per the below: 您需要按照以下说明更改“ GetGuarantorSummary”操作结果:

 public JsonResult GetGuarantorSummary([DataSourceRequest] DataSourceRequest request, string packageId, string packageProductId)
        {
           // GuarantorModel objGuarantorModel = new GuarantorModel();
            try
            {
                //Guarantors objGuarantors = new Guarantors(packageId, packageProductId);
                // objGuarantorModel = objGuarantors.GetGuarantorsSummary();
                //objGuarantorModel = GetGuarantorsStubbedData();
                List<EntryPointCRR.Models.GuarantorInfo> model = new List<EntryPointCRR.Models.GuarantorInfo>();
                //get your collection here:
                //TODO: My collection 
            }
            catch (Exception ex)
            {
                Logger.Write(ex, "General", 1, 1, System.Diagnostics.TraceEventType.Error);
            }
            return Json(model.ToDataSourceResult(request, ModelState), JsonRequestBehavior.DenyGet);
        }

To do this change make sure you have the following using statements 要进行此更改,请确保您具有以下using语句

using Kendo.Mvc.UI;
using Kendo.Mvc.Extensions;

Without these the DataSourceRequest Model and Extension methods will not work. 没有这些,DataSourceRequest模型和扩展方法将无法工作。

When returning your object back to the Grid make sure you are sending back a collection as that is what the grid is expecting and as you have indicated the grid is expecting the model type EntryPointCRR.Models.GuarantorInfo make sure this is the model type being sent back to the grid otherwise you will get a type mismatch. 在将对象返回到Grid时,请确保您要发送回一个集合,这正是该网格所期望的,并且如您所指出的,该网格期望模型类型EntryPointCRR.Models.GuarantorInfo确保这是正在发送的模型类型回到网格,否则您将得到类型不匹配的信息。

Hopefully this provides you with a way of getting you started any issues let me know. 希望这为您提供了一种方法,让您开始让我知道的任何问题。

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

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