【发布时间】:2017-05-31 05:22:04
【问题描述】:
我看到了引用here的例子
所以在我的应用程序中,我尝试以这种方式实现它:
HomeController
public ActionResult About([DataSourceRequest]DataSourceRequest request)
{
List<ShortDetail> listSD = new List<ShortDetail>();
... fill the list with objects
var v = listSD.ToDataSourceResult(request, sd => new ShortDetail { firstname = sd.firstname, surname = sd.surname, classname = sd.classname});
return Json(v, JsonRequestBehavior.AllowGet)
}
我的模型 ShortDetail
public class ShortDetail
{
public string firstname { get; set; }
public string surname { get; set; }
public int classid { get; set; }
public string classname { get; set; }
public string grade { get; set; }
public int studentid { get; set; }
public DateTime birthdate { get; set; }
public int? indicatorID { get; set; }
public string indicatorDescription { get; set; }
public List<ResultMergedWithType> results { get; set; }
}
在我的查看 About.cshtml
<div class="col-md-12 table-responsive" id="mapsDiv">
@(Html.Kendo().Grid<KendoExample.Models.ShortDetail>().Name("grid").DataSource(ds => ds.Ajax().Read(read => read.Action("About", "Home"))).Pageable())
</div>
现在我在浏览器中获取原始 json
或者,如果我尝试将模型与视图绑定
关于.cshtml
@model List<KendoExample.Models.ShortDetail>
@using Kendo.Mvc.UI
<div class="col-md-12 table-responsive" id="mapsDiv">
@(Html.Kendo().Grid<KendoExample.Models.ShortDetail>().Name("grid").DataSource(ds => ds.Ajax().Read(read => read.Action("About", "Home"))).Pageable())
</div>
HomeController
public ActionResult About([DataSourceRequest]DataSourceRequest request)
{
...
return View(listSD);
}
然后有一个空网格,其中包含模型 shortdetails 中定义的所有列,除了 ResultMergedWithType 属性
【问题讨论】:
-
您确定您在
var v = listSD.ToDataSourceResult(request, sd => new ShortDetail { firstname = sd.firstname, surname = sd.surname, classname = sd.classname});中获得值吗? -
是的,我在这两种情况下都在获取数据
标签: jquery ajax asp.net-mvc kendo-grid