Kendo UI MVC-基本的Ajax绑定 [英] Kendo UI MVC - basic ajax binding
问题描述
我在此处
因此,在我的应用程序中,我尝试通过以下方式实现它:
So in my application I try to implement it this way:
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
Now i get raw json in browser
或者,如果我尝试将模型与视图绑定
Alternatively if i try to bind the model with view
About.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);
}
然后,除了ResultMergedWithType属性
then there is an empty grid with all columns as defined in model shortdetails except the ResultMergedWithType property
推荐答案
我发现了我所缺少的..我们必须在Grid< ..>()构造函数中指定数据源
I found what I was missing..we have to specify a data source in Grid<..>() constructor
About.cshtml
@(Html.Kendo().Grid<KendoExample.Models.ShortDetail>(Model).Name("grid").DataSource(ds => ds.Ajax().Read(read => read.Action("About", "Home"))).Pageable())
HomeController
public ActionResult About([DataSourceRequest]DataSourceRequest request)
{
...
return View(listSD);
}
具有讽刺意味的是,尽管剑道支持团队无法帮助我解决这个问题.
It's ironic though that kendo support team was unable to help me with this problem.
干杯!
这篇关于Kendo UI MVC-基本的Ajax绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!