Kendo UI Grid只是呈现列标题。
网格不会渲染网格中的实际数据行。
这是我的代码。
public class CalculatorController : Controller
{
public ActionResult TimberData_Read()
{
var grades = new List<TimberGrades>();
grades.Add(new TimberGrades() { TimberGrade = "C14", BendingParallelToGrain = 4.1 });
grades.Add(new TimberGrades() { TimberGrade = "C16", BendingParallelToGrain = 5.3 });
var result = grades.AsQueryable();
return Json(result);
}
}
public class TimberGrades
{
public string TimberGrade { get; set; }
public double BendingParallelToGrain { get; set; }
public TimberGrades()
{
TimberGrade = "C14";
BendingParallelToGrain = 4.1;
}
}
在我的视图中,我尝试按如下方式渲染网格:
<div id="DivTimberGradeGrid">
@(Html.Kendo().Grid<TimberBeamCalculator.Models.TimberGrades>()
.Name("TimberGradeGrid")
.DataSource(ds => ds
.Ajax()
.Read(r => r.Action("TimberData_Read", "Calculator"))
)
.Columns(c=>
{
c.Bound(t => t.TimberGrade);
c.Bound(t => t.BendingParallelToGrain);
}
)
)
</div>
答案 0 :(得分:1)
我自己想出来了。
在我的控制器类中:
using Kendo.Mvc.Extensions;
.....
public ActionResult TimberData_Read([DataSourceRequest]DataSourceRequest request)
{
var grades = new List<TimberGrades>();
grades.Add(new TimberGrades() { TimberGrade = "C14", BendingParallelToGrain = 4.1 });
grades.Add(new TimberGrades() { TimberGrade = "C16", BendingParallelToGrain = 5.3 });
IQueryable<TimberGrades> res = grades.AsQueryable<TimberGrades>();
DataSourceResult res1 = res.ToDataSourceResult(request);
return Json(res1, JsonRequestBehavior.AllowGet);
}
....
and in the view
<p>
<div id="DivTimberGradeGrid">
@(Html.Kendo().Grid<TimberBeamCalculator.Models.TimberGrades>()
.Name("TimberGradeGrid")
.DataSource(ds => ds
.Ajax()
.Read(r => r.Action("TimberData_Read", "Calculator"))
)
.Columns(c=>
{
c.Bound(t => t.TimberGrade);
c.Bound(t => t.BendingParallelToGrain);
}
)
)
</div>
</p>