1

当我单击提交时,我希望传递在下拉框中选择的值。相反,它传递了一个空值,我对为什么感到困惑。任何帮助表示赞赏!

控制器:

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
4

2 回答 2

1

我不确定,但是如果您在 C# 中执行此操作,则可以将其FormCollection用作 ActionResult 的参数并从那里获取值。我就是这样做的

public ActionResult Index(FormCollection coll){
      var value1 = coll["SampleType"];
      var value1 = coll["Quarter"];

}

对不起,如果它在 VB 中不起作用,但也许值得一试?

于 2012-04-06T09:30:20.840 回答
0

您确定您的代码确实在您的 post 方法中传递吗?因为当我开始使用 asp.net(1 个月前)时,我遇到了问题。

我通过将 (Html.BeginForm()) 替换为 (Html.BeginForm(IsPost)) 解决了这个问题。

我不确定它是否会成功。

编辑 :

我也已经用过这个:

 Dim test1 As String = request("SampleType")
 Dim test2 As String = request("Quarter")
于 2012-04-05T23:28:57.540 回答