【发布时间】:2019-12-15 19:40:08
【问题描述】:
我正在使用 Telerik kendo 数据网格 如果我们查看以下内容,我正在使用 Web API 将数据返回到我的网格中。以下是我如何定义我的剑道读取方法,这个应用程序与我之前工作过的应用程序的唯一区别是我使用的是 .net core 3.1
我根据 Telerik 文档添加了这个。
https://docs.telerik.com/kendo-ui/knowledge-base/grid-is-not-showing-data 但网格中仍然没有数据,如下所示。
@(Html.Kendo().Grid<Stock>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(p => p.ID);
columns.Bound(p => p.Description).Width(180);
columns.Bound(p => p.Name).Width(180);
columns.Command(command => command.Destroy()).Width(160);
})
.ToolBar(toolbar =>
{
toolbar.Create();
toolbar.Save();
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Navigatable()
.Sortable()
.Groupable()
.Filterable()
.Scrollable()
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(20)
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Field(p => p.ID).Editable(false);
model.Field(p => p.Name);
})
.Read("ReadStock", "Stock")
)
)
public async Task<IActionResult> ReadStock([DataSourceRequest] DataSourceRequest request)
{
List<Stock> _result = new List<Stock>();
_result =await apiClient.GetStockFromApi();
object test = Json(_result);
return Json(_result);
}
如果我们查看下面的内容,您会发现我的数据很好。
但是当你看到我的网格时它是空的
我已经为 json.net 添加了正确的合约解析器,但我的网格中没有数据。在我的启动 cs 中,我有以下内容。
services
.AddControllersWithViews()
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
// Maintain property names during serialization. See:
// https://github.com/aspnet/Announcements/issues/194
.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
我的股票类。
public class Stock
{
public int ID { get; set; } // int, not null
public string StockCode { get; set; } // nvarchar(150), null
public string Name { get; set; } // nvarchar(350), not null
public string Description { get; set; } // nvarchar(max), null
public DateTime? StartDate { get; set; } // datetime, null
public DateTime? EndDate { get; set; } // datetime, null
public int? WarehouseId { get; set; } // int, null
public int? IsFreeText { get; set; } // int, null
public decimal? QuanityInStock { get; set; } // decimal(18,5), null
public decimal? RecordedQuantity { get; set; } // decimal(18,5), null
public bool? UseDescription { get; set; } // bit, null
public string Barcode { get; set; } // nvarchar(50), null
public int? ProductGroup { get; set; } // int, null
public int? TaxCode { get; set; } // int, null
public decimal? PhysicalStock { get; set; } // decimal(18,5), null
public decimal? ActualStock { get; set; } // decimal(18,5), null
public bool? isActive { get; set; } // bit, null
public bool? isDeleted { get; set; } // bit, null
public DateTime? CreatedDate { get; set; } // datetime, null
public string CreatedBy { get; set; } // varchar(100), null
public string UOM { get; set; } // nvarchar(50), null
}
【问题讨论】:
-
能否在浏览器中打开该页面,向我们展示服务器返回的实际响应? (开发者工具中的网络标签)
-
@Kei 是的,我会在目前刚上班的时候回家
-
@rogue39nin 你有没有找到解决方案?我遇到了类似的问题。
-
是的,这是因为我的 json 是以 camal 的形式出现的。但是网格需要普通情况 stackoverflow.com/a/58135043/651887 如果你调试你的 json 你会在控制台中注意到这一点
-
@Mark 在我自己对问题的回答中查看我的更新答案
标签: asp.net-core telerik kendo-grid kendo-asp.net-mvc