继续这个问题,我有一个表格,其中列出了一个人的所有车辆,车辆字段是可编辑的,它们现在已成功发回我的保存操作。
现在我想使用 UpdateModel 来保存数据,但我不确定如何构造它。这是我现在的保存操作:
<ActionName("Edit"), AcceptVerbs(HttpVerbs.Post)> _
Function Save(ByVal form As Person, ByVal vehicles() As Vehicle) As ActionResult
Dim original = From v In MyDataContext.Vehicles Where v.person_id = Person.person_id
For Each item In original
For i = 0 To vehicles.Count - 1
If vehicles(i).vehicle_id = item.vehicle_id Then
UpdateModel(item, New String() {"license_nbr", "color"})
Exit For
End If
Next
Next
MyDataContext.SubmitChanges()
Return RedirectToAction("Index", "Home")
End Function
当我运行它时,它不会保存任何东西,并且 UpdateModel 不会抛出任何错误。我假设我必须给它更多的方向才能让它发挥作用,因为 UpdateModel 不知道车辆数组中的哪个项目用于每次更新。
我是否需要将 ValueProviderResult 指定为 UpdateModel 的第三个参数?如果是这样,我如何从车辆(i)中创建一个?我是否完全不了解我的设置方式?