Kendo UI不会调用Action Result

时间:2015-10-27 18:20:20

标签: asp.net-mvc kendo-ui kendo-grid

我在ASp.NET 5中使用Kendo UI。我有一个动作方法来显示数据。它的 : 我不添加任何javascript代码,Do Need?

 public virtual ActionResult ReadData([DataSourceRequest] DataSourceRequest request)
    {
        request.Page = 1;
        IEnumerable<ShowProvinceVM> ddd = _provinceService.GetAll().Select(x => new ShowProvinceVM { Id = province.ProvinceId, Name = province.ProvinceName, NameEn = province.ProvinceNameEn, Code = province.ProvinceCode }).ToList();
        DataSourceResult result = ddd.ToDataSourceResult(request);
        result.Total = 20;
        return Json(result, "text/x-json", JsonRequestBehavior.AllowGet);
    }

显示网格数据的My Helper是:

@(Html.Kendo().Grid<CMS.ViewModel.Province.ShowProvinceVM>
()
.Name("grid2")
.DataSource(dataSource => dataSource
.Ajax()
    .Read(read => read.Action("ReadData", "Province"))
)
.Columns(columns =>
{
columns.Bound(c => c.Id);
columns.Bound(c => c.Name);

})

.Pageable()
.Sortable()

)

但是当我运行Project时,它是空的并且不会调用Action Methods。 什么问题 ? 当我将动作索引中的数据传递给View并编辑这样的Grid时,它会显示Data:

@(Html.Kendo().Grid(Model) //Bind the grid to ViewBag.Products
  .Name("grid")

  .Columns(columns =>
  {
      // Create a column bound to the ProductID property
      columns.Bound(product => product.Id);
      // Create a column bound to the ProductName property

      columns.Bound(product => product.Name);
  })
  .Pageable() // Enable paging

                      .Pageable()
                      .Sortable()

我的路线:

  routes.MapRoute(
            name: "lang",
            url: "{lang}/{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new string[] { "CMS.mvcApp.Controllers" }
        );
        routes.MapRoute(
            name: "langvalueparam",
            url: "{lang}/{controller}/{action}/{value}",
            defaults: new { controller = "Home", action = "Index", value = UrlParameter.Optional }, namespaces: new string[] { "CMS.mvcApp.Controllers" }
        );
        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new string[] { "CMS.mvcApp.Controllers" }
        );
        routes.MapRoute(
   "AdminDefault",
   "Admin/{controller}/{action}/{id}",
   new { area = "Admin", controller = "Home", action = "Index", id = UrlParameter.Optional }, namespaces: new string[] { "CMS.mvcApp.Areas.Admin.Controllers" });
        routes.MapRoute(
  "AdminPage",
  "Admin/{controller}/{action}/{page}",
  new { area = "Admin", controller = "Home", action = "Index", page = UrlParameter.Optional }, namespaces: new string[] { "CMS.mvcApp.Areas.Admin.Controllers" });

1 个答案:

答案 0 :(得分:0)

请注意,剑道发送它的读取请求为POST! 如果要使用GET(在使用JsonRequestBehavior.AllowGet时似乎),则需要定义请求类型。

.Read(read => read.Action("ReadData", "Province").Type(HttpVerbs.Get))