<HttpPost()> _
Function Create(ByVal cbadata As CBAData) As ActionResult
If ModelState.IsValid Then
db.CBADatas.Add(cbadata)
' db.SaveChanges()
Return RedirectToAction("Edit", "CBAData", cbadata)
End If
End Function
'
' GET: /CBAData/Edit/5
Function Edit(Optional ByVal id As Integer = Nothing) As ActionResult
Dim cbadata As CBAData = db.CBADatas.Find(id)
If IsNothing(cbadata) Then
Return HttpNotFound()
End If
ViewBag.idCustomer = New SelectList(db.Customers, "id", "Name", cbadata.idCustomer)
Return View(cbadata)
End Function
'
' POST: /CBAData/Edit/5
<HttpPost()> _
Function Edit(ByVal cbadata As CBAData) As ActionResult
If ModelState.IsValid Then
db.Entry(cbadata).State = EntityState.Modified
db.SaveChanges()
Return RedirectToAction("Index")
End If
ViewBag.idCustomer = New SelectList(db.Customers, "id", "Name", cbadata.idCustomer)
Return View(cbadata)
End Function
我正在尝试使用 Create 视图作为创建新 CBAData 项目的启动点。我希望他们选择一些简单的信息,然后继续进入编辑视图,如果模型有效,数据最终将被保存。
上面的代码不能正确导航。当它到达 db.CBADatas 上的 Find 方法时,它不存在于列表中。这可能吗?
是不是因为包括上下文在内的所有内容都为编辑视图而被处理和重新创建?