剑道网格读取动作方法不火

时间:2015-06-27 06:54:46

标签: kendo-ui grid kendo-grid

<div id="grid"></div>
(document).ready(function () {
    var dataSourceA = new kendo.data.DataSource({
        transport: {
            read: "../Test/CourseRead",
            dataType: "json"
        }
    });
    $("#grid").kendoGrid({
        dataSource: dataSourceA,
        height: 550,
        groupable: true,
        sortable: true,
        pageable: {
            refresh: true,
            pageSizes: true,
            buttonCount: 5
        },
        columns: [{
            field: "CourseName",
            title: "Course Name",
            width: 240
        }]
    });
});
 public ActionResult CourseRead([DataSourceRequest]DataSourceRequest request)
    {
        IQueryable<CourseInformationMasterViewModel> course = (from m in db.CourseInformationMasters
                                                               select new CourseInformationMasterViewModel{
                                                               CourseName=m.CourseName,
                                                               CourseCode=m.CourseCode,
                                                               CourseCredit=m.CourseCredit,
                                                               MasterCourseId=m.MasterCourseId
                                                               });
        DataSourceResult result = course.ToDataSourceResult(request);
        return Json(result);
    }

我的操作方法名称是CourseRead,控制器名称是Test.action方法正在触发,但显示一个空的grid.json结果返回值i chechk this.but网格为空。

2 个答案:

答案 0 :(得分:0)

它似乎是你的获取请求,默认为jsonResult doest

当你需要允许或使用get时,我们必须使用JsonRequestBehavior.AllowGet。

 public ActionResult CourseRead([DataSourceRequest]DataSourceRequest request)
    {
..
 return Json(new Modle.JsonResponseData { result, JsonRequestBehavior.AllowGet);
..
}

确保read: "../Test/CourseRead"调用您的控制器操作,否则您可以使用视图引擎从视图中调用您的操作..

答案 1 :(得分:0)

我得到了我的答案。我在我的行动方法中犯了错误。更新行动方法是:

 public JsonResult CourseRead()
    {
        var course = (from m in db.CourseInformationMasters
                      select new CourseInformationMasterViewModel
                      {
                          CourseName = m.CourseName,
                          CourseCode = m.CourseCode,
                          MasterCourseId = m.MasterCourseId
                      });
        return Json(course, JsonRequestBehavior.AllowGet);
    }