每當我從Respond.vbhtml
頁面提交我的表單時,控制器中的我的Respond_post
函數就會被調用;但是,在FormsRespondModel
中傳遞的項目是空的。MVC Model not binding to HTTPPost action
爲什麼我的帖子動作不填充我的FormsRespondModel,因爲它應該?
FormsRespondModel.vb
Public Class FormsRespondModel
Public Property form As cihForm
Public Property lists As cihLists = New cihLists()
Public Property subOrgs As List(Of cihOrganizationSub)
Public Property Events As List(Of cihEvent)
Public Sub New()
End Sub
Public Sub New(formId As String)
form = New cihForm()
form.loadForm(Guid.Parse(formId))
lists.loadOrganizationSubs(ZenCommon.CurrentOrgId, ZenCommon.CurrentUserId)
Dim emptyList() As String = {}
Dim eventsearchList As cihEventSearch = New cihEventSearch(ZenCommon.CurrentOrgId, "", DateTime.Now, ZenCommon.Date2050, True, emptyList, emptyList, emptyList)
Events = eventsearchList.eventList
subOrgs = lists.organizationSubs
End Sub
End Class
Respond.vbhtml
@ModelType CheckImHere.Student.FormsRespondModel
@Using Html.BeginForm()
@html.Hidden(Model.form.formId.ToString())
@For Each fld As Field In Model.form.fields
If fld.fieldTypeId = "text" Then
@<li>
<h4>@fld.title</h4>
<em>@fld.description</em>
<input type="text" placeholder="" value="@fld.response"/>
<em>@fld.isRequired</em>
</li>
End If
If fld.fieldTypeId = "para" Then
@<li>
<h4>@fld.title</h4>
<em>@fld.description</em>
@html.textarea(fld.response)
<em>@fld.isRequired</em>
</li>
End If
Next
<input type="submit" name="cmdSubmit" value="Submit" id="cmdSubmit"/>
End Using
RespondController.vb
<HttpPost>
<ActionName("Respond")>
Function Respond_post(viewModel As FormsRespondModel) As ActionResult
Return View("Respond", viewModel)
End Function