Kendo Grid取消编辑会删除该行

时间:2014-12-05 12:08:39

标签: ajax asp.net-mvc kendo-ui kendo-grid

我正在与Kendo Grid斗争,它是编辑弹出窗口。

当我按下编辑时,它会按预期显示弹出窗口,但是当我按下取消时它会删除行而不是什么都不做。

我的剑道网格如下:

@(Html.Kendo().Grid(Model.Where(x => x.OrgLevel == 0).First().DefinedFieldsList)
    .Name("DefinedlevelsGrid")
    .Columns(columns =>
    {           
        columns.Bound(x => x.FieldName).Title("Name");
        columns.Bound(x => x.FieldTypeText).Title("Type");
        columns.Bound(x => x.isMandatory).Title("Mandatory");
        columns.Bound(x => x.DefaultValue).Title("Default Value");
        columns.Bound(x => x.UpdatedOn).Title("Updated");
        columns.Bound(x => x.LevelGuid).Hidden();
        columns.Command(command => { command.Edit(); command.Destroy(); });
    })
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("_OrgDefinedFieldEdit"))
    .Pageable()
    .Sortable()
    .Events(events => events.Edit("GetLevelGuid"))                
    .DataSource(dataSource => dataSource
        .Ajax()
        .Model(model =>
            {
                model.Id(x => x.FieldId);
                model.Field(x => x.UpdatedOn).DefaultValue(DateTime.Now.ToString());
                model.Field(x => x.LevelGuid);
                model.Field(x => x.FieldType).DefaultValue(1);
            })
        .Create(create => create.Action("CreateDefinedField", "OrganisationAjax"))
        .Update(update => update.Action("EditDefinedField", "OrganisationAjax"))
        .Destroy(destroy => destroy.Action("DeleteDefinedField", "OrganisationAjax"))
    )
    .ToolBar(commands => commands.Create())
)

我使用模型填充它,但是当选择了相关的按钮列表时,则使用后续的ajax请求:

$(document).on('click', '.LevelSelector', function () {
    updateOrgDetails(this);
    var levelGuid = $(this).attr("LevelGuid").toString();

    var Url = '@Url.Action("GetLevelFields", "OrganisationAJAX")' + '?LevelGuid=' + levelGuid;

    $.ajax({
        url: Url,
        contentType: "application/json; charset=utf-8",
        type: 'POST',
        context: this,
        timeout: 60000,
        dataType: 'json',
        tryCount: 0,
        retryLimit: 3,
        success: function (data) {

            var grid = $("#DefinedlevelsGrid").data("kendoGrid");
            grid.dataSource.data(data);
        },
        error: function (httpRequest, textStatus, errorThrown) {
            $(".Message").text("Error: " + textStatus + " " + errorThrown);
        }
    });
});

回来的数据与字段名称匹配,所以我不确定问题是什么。

有没有人有任何想法?

编辑:这是一个返回的Json示例:

[{"FieldId":1,"FieldGuid":"12345","LevelId":3,"LevelGuid":"12345","FieldName":"Val","FieldType":1,"FieldTypeText":"Text","FieldTypeInput":null,"DefaultValue":"Val","Description":"Val","isMandatory":false,"CreatedOn":"1/12/2014 10:57","UpdatedOn":"1/12/2014 10:57","CreatedBy":"1","UpdatedValue":null,"HasData":false,"IsForAllSubNodes":true,"FieldTypesRef":[{"id":1,"Type":"Text"},{"id":2,"Type":"Numeric"},{"id":3,"Type":"Boolean"},{"id":4,"Type":"Date"}],"DefinedFieldData":null}

0 个答案:

没有答案