Erx*_*der 1 .net c# vb.net asp.net asp.net-mvc
ASP.NET MVC 2.0:简单模型绑定不能正常工作/绑定
我有一个简单的自定义对象名称注释(linq到sql生成一个),它有各种值,但只有两个值从HTML POST发送到我的操作,这是我接受它们的操作...
Function InsertComment(ByVal Comment As Comment) As ActionResult
' both CommentForPicID As Integer and Comment As String are the two values sent.
End Function
Run Code Online (Sandbox Code Playgroud)
textarea使用TextAreaFor命名,隐藏id用HiddenFor命名,我已经检查以确保我的Comment对象的属性名称与FORM元素的HTML ID/Name值完全匹配(case和all),两者都是CommentForPicID和没有任何前缀的评论.
我有一个断点来查看最新情况,当我的操作收到它时,在整个操作过程中,Comment对象始终设置为Nothing,并且最终在我尝试使用null对象时抛出异常.
我已经阅读过steven sandersons MVC框架的模型绑定部分,一切都应该是有序的,有没有人有任何想法?
...
附加信息(不需要读取): 但有趣的是,如果我将Comment对象包装在父对象中,比如说,CommentsParent包含一些东西并且Comment对象作为变量...那么我当然会更改表单元素使用apporpriate前缀的id,它然后按规定工作...但我这样做只是为了测试绑定是否正常工作,并且不希望/需要为我的应用程序执行此操作.
这是任何想要看到它的人的标记:
<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of FP.Comment)" %>
<%@ Import Namespace="FP" %>
<%--The line below is a workaround for a VB / ASPX designer bug--%>
<%=""%>
<% Html.EnableClientValidation()%>
<% Using Ajax.BeginForm("InsertComment", "Home", New AjaxOptions With {.UpdateTargetId = "InsertComment", .HttpMethod = FormMethod.Post})%>
<%= Html.HiddenFor(Function(x) x.CommentForPicID)%>
<%= Html.TextAreaFor(Function(x) x.Comment, 8, 40, New With {.style = "overflow: hidden;"})%><br />
<%= Html.ValidationMessageFor(Function(x) x.Comment)%>
<input type="submit" value="Save" name="SaveCancelButton"/>
<input type="submit" value="Cancel" name="SaveCancelButton" />
<% End Using %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1568 次 |
| 最近记录: |