У меня есть контроллер и строго типизированный вид в моем решении. В представлении у меня есть скрытое поле, которое изначально пустое. У меня есть форма в представлении, которое пользователь может нажать кнопку «Отправить», чтобы отправить форму в действие контроллера. В рамках действия контроллера я изменяю значение внутри модели, а затем повторно отображаю ту же форму (которая была ранее опубликована) с модифицированной моделью. В представлении я пишу значение поля модели внутри тега скрытого поля HTML, поэтому он будет виден на стороне javascript на стороне клиента. Проблема, с которой я сталкиваюсь, заключается в том, что в javascript значение скрытого поля в отложенной обратной форме пуст, даже если значение обратной ссылки на серверное значение задано правильно после обратной связи. Мне нужно, чтобы javascipt на стороне клиента мог видеть измененное значение скрытого поля. Что мне нужно сделать, чтобы это произошло?ASP.Net MVC Скрытое поле в форме postback
<HttpPost()> _
Function Index(ByVal model As MaxDocument, formcollection As FormCollection) As ActionResult
Dim sCriteria As String = ""
Dim nKeyIndex As Integer = 0
Dim nFieldIndex As Integer = -1
Dim sFieldValue As String = ""
Dim vrl As List(Of MaxServerLib.ValidationResult) = Nothing
Try
model.GetFileCabinetFieldList()
For nFieldIndex = 0 To (model.IndexFieldCount - 1)
sFieldValue = ""
If nFieldIndex > 0 Then
sCriteria += "~"
End If
Dim fcf As MaxServerLib.FileCabinetField = model.criterionAtIndex(nFieldIndex)
' Get the field value corresponding to this field
For Each oKey As Object In FormCollection.AllKeys
If oKey.ToString = fcf.sFieldName Then
sFieldValue = FormCollection(oKey.ToString)
Exit For
End If
Next
sCriteria += sFieldValue
Next
If sCriteria = "" Then sCriteria = "[BlankIndex]"
' First thing we do is to perform valiation of the criteria
model.ValidateFieldValues(sCriteria)
If Not model.AllFieldValuesValid() Then
' Handle case where one or more field values are invalid.
' In this case we want to redisplay the form but show an error message listing the invalid fields
' Populate the message to be displayed to the user
model.FormatErrorMessage()
' test code start
ModelState.Clear()
' test cod end
' Return RedirectToAction("Index", New With {.sMaxUrl = model.MaxUrl, .sDataSource = model.DataSource, .sSessionTicket = model.SessionTicket, .dtLastCall = model.LastCall, .sFileCabinetid = model.FileCabinetId, .sFileCabinetName = model.FileCabinetName, .sShowMsg = MaxServerLib.EscapeString(model.ShowMsg)})
Return View(model)
Else
' All field values are valid, now attempt to add the document
If model.ExportDocument() Then
' Document export was successful
System.Diagnostics.Debugger.Break()
Else
' Document export failed for some reason
ModelState.AddModelError("", model.LastError)
Return View(model)
End If
End If
' Return RedirectToAction("Index", "SearchResults", New With {.sMaxUrl = model.MaxUrl, .sDataSource = model.DataSource, .sSessionTicket = model.SessionTicket, .dtLastCall = model.LastCall, .sFileCabinetId = model.FileCabinetId, .sFileCabinetName = model.FileCabinetName, .sSearchCriteria = sSearchCriteria})
Catch ex As Exception
System.Diagnostics.Debugger.Break()
End Try
'End If
' If we got this far, something failed, redisplay form
Return View(model)
End Function
показать разметку вида, связанную с скрытым полем – Igor
Практически невозможно помочь, не увидев некоторую разметку, Брайан. –
Просмотр разметки для скрытого поля: @ –