【问题标题】:Performing An Inline Edit With A Kendo Grid Using Angular.js, Kendo UI and ASP.NET MVC使用 Angular.js、Kendo UI 和 ASP.NET MVC 使用 Kendo Grid 执行内联编辑
【发布时间】:2016-10-30 01:40:39
【问题描述】:

我正在使用 Angular.js、Kendo UI、ASP.NET MVC 和 C#。我有一个 Kendo Grid,我想在其上执行内联编辑。当我单击网格中的编辑按钮,更新行中的数据,然后单击更新按钮时,请求被发送到服务器并点击我的 MVC 控制器方法,但请求中没有传回数据。我需要更改哪些内容才能使内联编辑正常工作?

<section ng-app="manageProjectsApp" ng-controller="manageProjectsController as vm">
    <div kendo-grid="grid" options="vm.kendoGridOptions"></div>
</section>

<script>
    ...

    vm.kendoGridOptions = {
        scrollable: false,
        sortable: true,
        pageable: false,
        editable: 'inline',
        columns: [{
            field: 'ProjectName',
            title: 'Project Name'
        }, {
            field: 'Active',
            title: 'Is Active?'
        }, {
            command: ['edit']
        }],
        dataSource: new kendo.data.DataSource({
            transport: {
                read: {
                    url: '/manage-projects/get-projects',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json'
                }, update: {
                    url: '/manage-projects/update-project',
                    type: 'POST',
                    dataType: 'json',
                    contentType: 'application/json'
                }, parameterMap: function (options, operation) {
                    if (operation !== 'read' && options.models) {
                        return {
                            models: kendo.stringify(options.models)
                        };
                    }
                }
            }, schema: {
                model: {
                    id: 'ProjectId',
                    fields: {
                        ProjectId: {
                            type: 'number',
                            editable: false,
                            nullable: false
                        },
                        ProjectName: {
                            type: 'string',
                            nullable: false,
                            validation: {
                                required: true
                            }
                        },
                        Active: {
                            type: 'boolean',
                            nullable: false
                        }
                    }
                }
            }
        })
    };
</script>

[Route("manage-projects/update-project")]
public JsonResult UpdateProject(ProjectData projectData)
{
  // save the data...

  return Json(true, JsonRequestBehavior.DenyGet);
}

public class ProjectData
{
  public int ProjectId { get; set; }
  public string ProjectName { get; set; }
  public bool Active { get; set; }
}

【问题讨论】:

    标签: c# angularjs asp.net-mvc kendo-ui kendo-grid


    【解决方案1】:

    我会说从您的 Json 结果中删除 JsonRequestBehavior.DenyGet。此外,如果它是 POST 方法,请使用 [HttpPost] 属性标记您的方法。

    【讨论】:

      猜你喜欢
      • 2016-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多