即使没有数据更新,如何强制Kendo网格更新

时间:2013-10-01 11:38:58

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

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

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

@(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))

                )

1 个答案:

答案 0 :(得分:4)

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

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

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

如果无法做到这一点,您可以通过执行以下操作强制dataItem获取true

dirty

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