当我单击提交时,我希望传递在下拉框中选择的值。相反,它传递了一个空值,我对为什么感到困惑。任何帮助表示赞赏!
控制器:
Namespace DHR
Public Class WorkSampleController
Inherits System.Web.Mvc.Controller
Private dbQ As QuarterDBContext = New QuarterDBContext
Private db As WorkSampleDBContext = New WorkSampleDBContext
Function Index() As ViewResult
Dim quarterList As New List(Of String)()
Dim QuarterQry = From d In dbQ.getQuarter
Order By d.ID
Select d.Quarter
quarterList.AddRange(QuarterQry.Distinct())
ViewBag.Quarter = New SelectList(quarterList)
Return View(db.WorkSample.ToList())
End Function
<HttpPost()>
Function Index(ByVal quarterID As Integer) As ActionResult
Dim quarter As String = "null"
If quarterID = 1 Then
quarter = "Dec, Jan, Feb"
End If
ViewBag.test = quarter
Return View()
End Function
看法:
@ModelType IEnumerable(Of DHR.WorkSample)
@Code
ViewData("Title") = "Monitor"
Using (Html.BeginForm())
@<p> Type: @Html.DropDownList("SampleType")
Quarter: @Html.DropDownList("Quarter")
<input type="submit" value="Filter" /></p>
End Using
End Code