使用从AJAX创建调用返回的/值更新网格

时间:2014-01-14 20:44:01

标签: kendo-ui kendo-grid

我有一个Kendo网格,可以对MVC方法进行AJAX编辑。该方法返回网格行模型的新副本,其中包含在服务器上执行的一些计算。有没有办法在收到编辑结果后用这些数据更新网格?

这是我的网格代码

    @(Html.Kendo().Grid(Of AssemblyPartListRowViewModel) _
        .Name("parts") _
        .ToolBar(Sub(toolbar)
                         toolbar.Create().Text("Add Part to Assembly")
                 End Sub) _
        .DataSource(Sub(config)
                            config _
                            .Ajax() _
                            .Events(Sub(events) events.Error("parts_Error")) _
                            .Model(Sub(model)
                                           model.Id(Function(x) x.AssemblyPartDefID)
                                           model.Field(Function(x) x.PartNumber)
                                           model.Field(Function(x) x.Description).Editable(False)
                                           model.Field(Function(x) x.Cost).Editable(False)
                                           model.Field(Function(x) x.ResaleValue).Editable(False)
                                           model.Field(Function(x) x.TotalResaleValue).Editable(False)
                                   End Sub) _
                            .Read("PartList", "Assembly", New With {.id = Model.AssemblyID}) _
                            .Destroy("RemovePart", "Assembly") _
                            .Create(Sub(create)
                                            create.Action("AddPart", "Assembly")
                                            create.Data("function() { return { assemblyId: " & Model.AssemblyID & " }; }")
                                    End Sub) _
                            .Update("UpdatePart", "Assembly")
                    End Sub) _
        .Columns(Sub(config)
                         config.Bound(Function(x) x.PartsQuantity).Width(20).Title("Quantity")
                         config.Bound(Function(x) x.PartNumber).Title("Part Number")
                         config.Bound(Function(x) x.Description).Title("Part Description")
                         config.Bound(Function(x) x.Cost).Format("{0:C}")
                         config.Bound(Function(x) x.ResaleValue).Title("Resale").Format("{0:C}")
                         config.Bound(Function(x) x.TotalResaleValue).Title("Line Total").Format("{0:C}")
                         config.Command(Sub(command)
                                                command.Destroy().Text("delete")
                                                command.Edit()
                                        End Sub)
                 End Sub)
    )

这是我的控制器中的create方法

    '
    ' POST: /Assembly/AddPart

    <HttpPost()> _
    Public Function AddPart(model As AssemblyPartListRowViewModel) As ActionResult
        Dim partDef As AssemblyPartDef = DataSource.AssemblyPartDefs.LoadNew(model)
        DataSource.SaveChanges()

        Return Json(GetAssemblyPartListModel(partDef))
    End Function

0 个答案:

没有答案