5

我正在尝试为剑道网格中的产品上传图片(内联编辑)。在插入它工作正常。在更新中,它不允许我只更改图像。单击更新按钮后,除非我更改其他字段之一,否则它不会进入控制器。

因此,如果有办法强制更新按钮转到控制器,那将会很有帮助。

@(Html.Kendo().Grid(Model)
    .Name("BrandGrid")
                    .Events(e => e.Edit("edit").DataBound("onDataBound").Cancel("onDataBound")) 
            .DataSource(dataSource => dataSource

                .Ajax()
                .ServerOperation(true)
                .Events(events => events.Error("error_handler"))


                .PageSize(10)
                   .Model(  model =>{
                       model.Id(p => p.BrandID);
                       model.Field(p => p.BrandID).Editable(false);


                   })

                   .Update(update => update.Action("Brand_Update", "Brands"))
                   .Create(insert => insert.Action("Brand_Insert", "Brands"))
                   .Read(read => read.Action("Brand_Read", "Brands"))
                   .Destroy(delete => delete.Action("Brand_Delete", "Brands"))

            )
         .Columns(columns =>
         {
             columns.Bound(p => p.BrandID).Groupable(false).Title(MyResources.LabelBrandID).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
             columns.Bound(p => p.BrandNameE).Title(MyResources.LabelBrandNameE).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
             columns.Bound(p => p.BrandNameA).Title(MyResources.LabelBrandNameA).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
             columns.Bound(p => p.BrandID).Width(120).Title(" ").Filterable(false)
            .ClientTemplate(@"<img alt='Brand Image' src='" + Url.Content("~/Images/Brands/") + "#=data.BrandID#.jpg' alt=\"${data.BrandID}\" />");

             columns.Template(@<text></text>).Title(" ").ClientTemplate("<input type=file name='files' onchange='dataBound(this.value)' />").Width(280).Hidden(true);                 
             columns.Command(command => { command.Edit().Text(MyResources.EditText).CancelText(MyResources.CancelText).UpdateText(MyResources.UpdateText); command.Destroy().Text(MyResources.Delete); });



         })

                             .ToolBar(toolbar => toolbar.Create().Text(MyResources.AddNewItem))
                     .Pageable(pager => pager
                    .Numeric(true)
                        .PreviousNext(true)
                        .Refresh(true)
                        .PageSizes(true)
                  )



                             .Filterable(filterable => filterable
                                .Extra(true)
                                .Operators(operators => operators
                                   .ForString(str => str.Clear()
                                   .StartsWith(MyResources.StartsWith)
                                   .IsEqualTo(MyResources.IsEqualTo)
                                   .IsNotEqualTo(MyResources.IsNotEqualTo)
                                   .Contains(MyResources.Contains)
                                   .DoesNotContain(MyResources.DoesNotContain)
                                   .EndsWith(MyResources.EndsWith)
                                    )
                                   .ForNumber(num => num.IsEqualTo(MyResources.IsEqualTo).IsGreaterThan(MyResources.IsGreaterThan).IsNotEqualTo(MyResources.IsNotEqualTo).IsGreaterThanOrEqualTo(MyResources.IsGreaterThanOrEqualto).IsLessThanOrEqualTo(MyResources.IsLessThanOrEqualTo).IsLessThan(MyResources.IsLessThan))
                                   )

                              .Messages(messages => messages.Info(MyResources.Info).Filter(MyResources.Filter).Clear(MyResources.Clear).And(MyResources.And).Or(MyResources.Or))
                                  )

                           .Pageable(pager => pager.Messages(messages => messages.Display(MyResources.Display).Empty(MyResources.Empty).First(MyResources.GoToTheFirstPage).Last(MyResources.GoToTheLastPage).Next(MyResources.GoToTheNextPage).Previous(MyResources.GoToThePreviousPage).Of(MyResources.of).Page(MyResources.page).ItemsPerPage(MyResources.ItemsPerPage).Refresh(MyResources.Refresh)))


                .Selectable(selectable => selectable
                .Mode(GridSelectionMode.Multiple))
                .Navigatable()
                .Sortable()
                .Scrollable(scr => scr.Height(405))
                .Resizable(resize => resize.Columns(true))
                //.HtmlAttributes(new { style = "height:430px;" })
                                        .Editable(editablee => editablee.Mode(GridEditMode.InLine).DisplayDeleteConfirmation(MyResources.DeleteConfirmMessage))

                )
4

1 回答 1

8

Kendo UI 仅在记录时更新记录,dirty这意味着模型中的某些字段已被修改。

如果不改变模型而是直接改变数组中的数据,那么 KendoUI 并不知道记录实际上已经被修改(这就是为什么我们必须使用set, 来控制是否dirty需要切换到true)。

不确定您如何更改图像我同意@PeturSubev,如果您共享代码可能会更容易,因为我们可以看到问题所在。

如果这是不可能的,您可以强制 dataItemdirty通过执行以下操作:

// item is the reference to the data in the Grid DataSource
data.dirty = true;
$("#grid").data("kendoGrid").saveChanges();

此处的示例:http: //jsfiddle.net/OnaBai/pPkWc/

于 2013-10-01T21:48:00.653 回答