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

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

问题描述

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

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.

这是我的观点:

<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>

这是我的控制器:

[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.

谢谢

推荐答案

(只需为您回答上一个答案即可)

(Just to expand on the previous answer for you)

在默认状态下读取网格时,网格实际上会执行发布.运行提琴手时,您会看到此信息.因此,通过使用Http.GET对其进行标记,就永远不会调用该操作.除非您已告知read动作发送get请求而不是post请求.

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);   
}

注意,我已删除了http动词.如果需要,您可以稍后将其应用回去.

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

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

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