私はこのASP.net MVCのことは初めてで、ListBoxForとDropDownListForに本当に行き詰まっています。
それらをどのように使用しますか?例はありますか?
私はこのASP.net MVCのことは初めてで、ListBoxForとDropDownListForに本当に行き詰まっています。
それらをどのように使用しますか?例はありますか?
それは本当に難しいことではありません。いつものように、ビュー モデルを定義することから始めます。
Public Class MyViewModel
    Public Property SelectedItems As IEnumerable(Of String)
    Public Property SelectedItem As String
    Public Property Items As IEnumerable(Of SelectListItem)
End Class
次にコントローラー:
Public Class HomeController
    Inherits System.Web.Mvc.Controller
    Function Index() As ActionResult
        Dim model = New MyViewModel With {
            .Items = {
                New SelectListItem() With {.Value = "1", .Text = "item 1"},
                New SelectListItem() With {.Value = "2", .Text = "item 2"},
                New SelectListItem() With {.Value = "3", .Text = "item 3"}
            }
        }
        Return View(model)
    End Function
    Function Index(model As MyViewModel) As ActionResult
        ' Here you can use the model.SelectedItem which will
        ' return you the id of the selected item from the DropDown and 
        ' model.SelectedItems which will return you the list of ids of
        ' the selected items in the ListBox.
        ...
    End Function
End Class
最後に、対応する厳密に型指定されたビュー:
@ModelType MvcApplication1.MyViewModel
@Using Html.BeginForm()
    @Html.DropDownListFor(Function(x) x.SelectedItem, Model.Items)
    @Html.ListBoxFor(Function(x) x.SelectedItems, Model.Items)
    @<input type="submit" value="OK" />
End Using