简体   繁体   English

MVC 中的 Kindo Grid 显示原始数据

[英]Kindo Grid in MVC is displaying raw data

I'm new to Kendo and learning how to integrate it with MVC and display data in a grid.我是 Kendo 的新手,正在学习如何将它与 MVC 集成并在网格中显示数据。

My controller我的控制器

[HttpGet]
public ActionResult StudentList([DataSourceRequest]DataSourceRequest request)
{
    DataSourceResult result = 
    _acc.GetStudent(StudId).ToDataSourceResult(request,
        model => new StudentModel
        {
            ID = model.ID,
            StudId = model.StudId,
            Name= model.Name,
            Email= model.FullName,
            custEmail = model.Email
        });


        return Json(result, JsonRequestBehavior.AllowGet);
}

My view我的看法

@(Html.Kendo().Grid<Models.StudentModel>()
                .Name("grid")
                .Columns(columns =>
                {
                    columns.Bound(c => c.StudId);
                    columns.Bound(c => c.Name);
                    columns.Bound(c => c.Email);
                })
                     .Pageable()
                     .Sortable()
                     .Filterable()
                     .Scrollable(scr => scr.Height(550))
                     .DataSource(dataSource => dataSource
                     .Ajax()
                     .Read(read => read.Action("StudList", "Student"))
                     .ServerOperation(false)
  )
)

And the out put I am getting in my browser looks like我在浏览器中得到的输出看起来像

{"Data":[{"ID":1102,"StudId":4006,"Name":"Adam Lyon","Email":"alyon@regionofwaterloo.ca",",....,

Does anyone has any idea why the data is not formatted in a grid form?有谁知道为什么数据没有以网格形式格式化?

You will get that behavior if you link directly to the EmployeeList action - that should only be called by the grid.如果您直接链接到 EmployeeList 操作,您将获得该行为 - 仅应由网格调用。 If your view name is say Index , you will need another action:如果您的视图名称是Index ,您将需要另一个操作:

public ActionResult Index()
{
    return View();
}

Then in code link to that:然后在代码链接中:

@Html.ActionLink("Employee List", "Index", "Employee")

Now the view will load and the Kendo grid will render and then call your EmployeeList action to populate the grid.现在视图将加载,Kendo 网格将呈现,然后调用您的 EmployeeList 操作来填充网格。

See the Kendo sample controller here .请参阅此处的 Kendo 示例控制器。 It has an action to load the view with the grid, and then CRUD actions the grid will call via AJAX.它有一个动作用网格加载视图,然后网格将通过 AJAX 调用 CRUD 动作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM