MVC Kendo Grid 不显示任何数据 [英] MVC Kendo Grid not showing any data

查看:23
本文介绍了MVC Kendo Grid 不显示任何数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Kendo UI Grid 服务器端包装器,并尝试将一些数据从我的模型加载到其中.网格正在页面上呈现,但没有填充数据.我没有经常使用这个网格,所以我想我只是缺少 ClientTemplate 的一些东西.我已经查看了 Kendo 文档,但还没有任何运气.

这是我的观点:

<div id="网格">@(Html.Kendo().Grid().Name("网格").DataSource(dataSource => 数据源.Ajax().Read(read => read.Action("KendoGrid", "Dependents")).ServerOperation(假)).Columns(columns =>{column.Bound(d => d.MaskedSSN).ClientTemplate("<#: MaskedSSN #>").Title("SSN");columns.Bound(d => d.FirstName).ClientTemplate("<#: FirstName #>").Title("First Name");columns.Bound(d => d.LastName).ClientTemplate("<#: LastName #>").Title("Last Name");columns.Bound(d => d.DateOfBirth).ClientTemplate("<#: DateOfBirth #>").Title("出生日期");column.Bound(d => d.Gender).ClientTemplate("<#: Gender #>").Title("Gender");column.Bound(d => d.DependentTypeId).ClientTemplate("<#: DependentTypeId #>").Title("Type");}).Pageable().Sortable().HtmlAttributes(new {style = "height: 400px;"}))

这是我的控制器:

[HttpGet]公共 ActionResult KendoGrid([DataSourceRequest]DataSourceRequest 请求){DataSourceResult 结果 = UnitOfWork.Enrollment.Dependents.ToDataSourceResult(request,模型 =>新的依赖模型{SSN = 模型.SSN,名字 = 模型.名字,姓氏 = 模型.姓氏,出生日期 = 模型.出生日期,性别 = 模型.性别,DependentTypeId = model.DependentTypeId});返回视图(结果);}

有人可以告诉我我遗漏了什么或我做错了什么吗?如果您需要更多信息,请告诉我.就像我说的,网格在页面上呈现所有正确的列标题,应该有一行但不存在数据.它只是说没有要显示的项目".

谢谢

解决方案

(只是为您扩展上一个答案)

网格在默认状态下阅读时实际上会执行一个帖子.运行 fiddler 时您会看到这一点.因此,通过使用 Http.GET 标记此操作,永远不会调用该操作.除非您已告诉读取操作发送获取请求而不是发布请求.

尝试将您的控制器更改为:

public JsonResult KendoGrid([DataSourceRequest]DataSourceRequest request){DataSourceResult 结果 = UnitOfWork.Enrollment.Dependents.ToDataSourceResult(request,模型 =>新的依赖模型{SSN = 模型.SSN,名字 = 模型.名字,姓氏 = 模型.姓氏,出生日期 = 模型.出生日期,性别 = 模型.性别,DependentTypeId = model.DependentTypeId});返回 Json(result,JsonRequestBehavior.AllowGet);}

注意我已经删除了 http 动词.如果你愿意,你可以在之后应用它.

I'm using the Kendo UI Grid server-side wrapper and attempt to load some data into it from my model. The grid is rendering on the page but no data is being populated. I haven't used this grid that much so I think I'm just missing something with the ClientTemplate. I've reviewed the Kendo docs but haven't had any luck yet.

Here is my View:

<div id="dependents">
    <div id="grid">
        @(Html.Kendo().Grid<Enrollment.Models.DependentModel>()
              .Name("grid")
              .DataSource(dataSource => dataSource
                  .Ajax()
                  .Read(read => read.Action("KendoGrid", "Dependents"))
                  .ServerOperation(false)
              )
              .Columns(columns =>
              {
                  columns.Bound(d => d.MaskedSSN).ClientTemplate("<#: MaskedSSN #>").Title("SSN");
                  columns.Bound(d => d.FirstName).ClientTemplate("<#: FirstName #>").Title("First Name");
                  columns.Bound(d => d.LastName).ClientTemplate("<#: LastName #>").Title("Last Name");
                  columns.Bound(d => d.DateOfBirth).ClientTemplate("<#: DateOfBirth #>").Title("Date of Birth");
                  columns.Bound(d => d.Gender).ClientTemplate("<#: Gender #>").Title("Gender");
                  columns.Bound(d => d.DependentTypeId).ClientTemplate("<#: DependentTypeId #>").Title("Type");
              })
              .Pageable()
              .Sortable()
              .HtmlAttributes(new {style = "height: 400px;"})
              )
    </div>

Here is my Controller:

[HttpGet]
    public ActionResult KendoGrid([DataSourceRequest]DataSourceRequest request)
    {
        DataSourceResult result = UnitOfWork.Enrollment.Dependents.ToDataSourceResult(request,
            model => new DependentModel
            {
                SSN = model.SSN,
                FirstName = model.FirstName,
                LastName = model.LastName,
                DateOfBirth = model.DateOfBirth,
                Gender = model.Gender,
                DependentTypeId = model.DependentTypeId
            });
        return View(result);   
    }

Can someone please let me know what I'm missing or what I'm doing wrong? If you need more info just let me know. Like I said, the grid renders on the page with all the correct column headings and there should be one row but no data is present. It just says "No items to display" in it.

Thanks

解决方案

(Just to expand on the previous answer for you)

The grid actually performs a post when it is reading in it's default state. You will see this when running fiddler. So by tagging this with Http.GET the action is never called. Unless you have told the read action to send a get request rather than a post request.

Try changing your controller to this:

public JsonResult KendoGrid([DataSourceRequest]DataSourceRequest request)
{
    DataSourceResult result = UnitOfWork.Enrollment.Dependents.ToDataSourceResult(request,
        model => new DependentModel
        {
            SSN = model.SSN,
            FirstName = model.FirstName,
            LastName = model.LastName,
            DateOfBirth = model.DateOfBirth,
            Gender = model.Gender,
            DependentTypeId = model.DependentTypeId
        });


    return Json(result,JsonRequestBehavior.AllowGet);   
}

Notice I have removed the http verb. You can apply this back afterwards if you want.

这篇关于MVC Kendo Grid 不显示任何数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆