我的表格有几行数据,我需要回到控制器。 我认为,我最初通过选定一个期限和点击一个吨来填表。 表格载有我的所有相关记录,但我的桌子之一载有一份下级清单。 因此,我应该能够选择点击“更新日期”,我的控制者可以避免变化。
因此,在我尝试和挽救之前,一切都发挥了作用。 发给控制员的模式完全无效。 我与桌子捆绑在一起的财产归还控制人。
@ModelType SuperViewModel
//We need this a view model in order to store a List of the models in the table
@Using (Html.BeginForm())
@For Each i in Model.CompleteList
Dim currentItem = i //MVC auto-generated extra declarations. Seems redundant to me but it works.
@<table>
<tr>
<td>@Html.DisplayFor(function(Model)currentItem.Name)</td>
<td>@Html.DisplayFor(function(Model)currentItem.SampleTime)</td>
<td>@Html.DropDownListFor(function(Model)currentItem.WorkTime, ViewBag.WorkTimeList)</td>
</tr>
Next
</table>
<input name="submit" type="submit" value="Update"/>
End Using
//Controller
<HttpPost()>
function Save(vmodel as SuperViewModel, submit as String) as ActionResult //NOTE: submit parameter is used because we have two submit buttons but its not relevant here
if submit = "Update"
db.Entry(vmodel.CompleteList).State = EntityState.Modified//Here the exception is throw because our list is null at this point even tho its tied to the model in the view.
db.SaveChanges()
end if
End Function
NOTE: This is written in VB. 该网络,但C#帮助值得欢迎。 我熟悉MVC两种语言。