为什么我的KendoGrid叫我的MVC控制器? [英] Why doesn't my KendoGrid call my MVC controller?

查看:134
本文介绍了为什么我的KendoGrid叫我的MVC控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标准的C#ASP.NET MVC控制器的以下code。

I have the following code in a standard C# ASP.NET MVC controller.

public JsonResult ReadTeachers()
{
    return Json(ReadTeacherData(), JsonRequestBehavior.AllowGet);
}

public void UpdateTeachers(IEnumerable<Teacher> updatedTeachers)
{
    // this is never called
}

我试图调用这个控制器与KendoGrid。这里是code为我的网格。

I'm trying to call this controller with a KendoGrid. Here is the code for my grid.

$("#teachers").kendoGrid({
    dataSource: {
        type: "json",
        transport: {
            read: {
                url: '@Url.Action("ReadTeachers", "EducationPortal")',
                dataType: "json"
            },
            update: {
                url: '@Url.Action("UpdateTeachers", "EducationPortal")',
                dataType: "json"
            },
            parameterMap: function (options, operation) {
                if (operation !== "read" && options.models) {
                    return { models: kendo.stringify(options.models) };
                }
            }
        },
        batch: true,
        schema: {
            model: {
                id: "TeacherId",
                fields: {
                    TeacherId: { type: "number" },
                    FullName: { type: "string" },
                    IsHeadmaster: { type: "boolean" }
                }
            }
        }
    },
    toolbar: ["create", "save"],
    columns: [
        { field: "FullName", title: "Teacher" },
        { field: "IsHeadmaster", title: "Is a Headmaster?", width: "120px" },
        { command: ["destroy"], title: "&nbsp;", width: "85px" }],
    editable: true
});

我适应这个code从剑道的范例 。问题是,该UpdateTeachers方法不会被调用。我怀疑问题出在parameterMap的功能,因为这是code我了解最少的部分。

I adapted this code from Kendo's examples. The problem is, the UpdateTeachers method is never called. I suspect that the issue lies in the parameterMap function, because that's the part of the code I understand the least.

推荐答案

而不是使用

public void UpdateTeachers(IEnumerable<Teacher> updatedTeachers)
{
    // this is never called
}

public JsonResult UpdateTeachers(string models)
{
//Deserialize to object
IList<Teacher> teachers= new JavaScriptSerializer().Deserialize<IList<Teacher>>(models);

return Json(Teacher)
}

需要注意的是parameterMap的:()函数发送更新的数据序列化字符串格式名称为模式,所以你应该在你的动作用模型作为参数名

Note that parameterMap: function() send updated data in serialize string format with name models so you should use "models" as parameter name in your action

我希望这会帮助你。

这篇关于为什么我的KendoGrid叫我的MVC控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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