【发布时间】:2016-12-14 13:17:03
【问题描述】:
我正在开发一个 ASP.net MVC 项目,我需要使用 KendoUI Grid 功能显示来自数据库的数据。它运行良好,但每当我在数据表列名中添加点时,它什么都不显示。我试图序列化它们以避免这个问题,但它仍然无法正常工作。这是我的代码,
public ActionResult Read([DataSourceRequest] DataSourceRequest request)
{
DataTable products = Products();
var result = JsonConvert.SerializeObject(products.ToDataSourceResult(request));
return Json(result, JsonRequestBehavior.AllowGet);
}
public DataTable Products()
{
// Here we create a DataTable with four columns.
DataTable table = new DataTable();
table.Columns.Add("Dosage.Dosage", typeof(int));
table.Columns.Add("Drug", typeof(string));
table.Columns.Add("Patient", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
// Here we add five DataRows.
table.Rows.Add(25, "Indocin", "David", DateTime.Now);
table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);
return table;
}
这是我的网格,
@model System.Data.DataTable
<div class="container-fluid">
<div class="row">
<div class="col-xs-18 col-md-12">
@(Html.Kendo().Grid<dynamic>()
.Name("grid")
.Columns(columns =>
{
})
.Pageable()
.Sortable()
.Scrollable()
.Filterable()
.HtmlAttributes(new { style = "height:550px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Read(read => read.Action("Read", "Home"))
)
)
</div>
</div>
【问题讨论】:
-
您应该显示您的网格定义以显示模型/模式设置。此外,点不是 javascript 字段/变量名称中的有效字符……您的数据最终会成为客户端的 javascript 对象。
-
但在我的数据库中,我有像 "Dosage.Dosage" 这样的列名。在这种情况下,如何显示该列的数据? @TheDreadPirateStephen
-
请显示您当前的网格定义,以便我们了解您的起点。
-
我已将其添加到我的帖子中。 @TheDreadPirateStephen
标签: asp.net kendo-ui kendo-grid kendo-asp.net-mvc