我错过了什么吗?以下是想要查看其相关部分的代码...
<% Using Ajax.BeginForm("UpdateComment", "Home",
New AjaxOptions With {.UpdateTargetId = Model.CommentDivId,
.HttpMethod = FormMethod.Post})%>
并且...
<%= Html.HiddenFor(Function(x) x.Comment.CommentID)%>
<%= Html.TextAreaFor(Function(x) x.Comment.Comment, 8, 40,
New With {.style = "overflow: hidden;"})%>
<%= Html.ValidationMessageFor(Function(x) x.Comment.Comment) %>
这里是Action方法,当我尝试使用对象时,它会引发一个错误...错误是空引用异常:
Function UpdateComment(ByVal UpCom As Comment) As ActionResult
Dim db = New FPicDataContext ' 在数据库中查找符合条件的记录 Dim Updatable = (From c In db.Comments Where c.CommentID = UpCom.CommentID).FirstOrDefault ' 更新记录内容 Updatable.Comment = UpCom.Comment ' 这里出现了对象为空的错误!基本上,UpCom 中的所有值(作为 Comment)都是 0 或 Null。 ' 提交更改到数据库 db.SubmitChanges()
Dim cm = New CommentModel With {.Comment = UpCom, .CommentDivId = "CommentDiv" & UpCom.CommentID.ToString}
Return PartialView("Comment", cm)
End Function