1

I'm looking to pass the value selected in the drop box when I click submit. Instead, it's passing a null value and I'm confused as to why. Any help is appreciated!!

Controller:

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

View:

@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

Im not sure, but if you do it in C# you could use the FormCollection as an inparameter to the ActionResult and get the value from there. this is how I would do it

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

}

Im sorry if it not works in VB but mabye its worth a shot?

于 2012-04-06T09:30:20.840 に答える
0

Are you sure your code does really pass inside your post method? Because when I began asp.net (1 month ago), I had a problem with it.

I solved this by replacing (Html.BeginForm()) by (Html.BeginForm(IsPost)).

I'm not sure whether it will do the trick or not.

edit :

I've also already used this :

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