VB中的MVC.NET-选择要Html.Dropdownlist的列表 [英] MVC.NET in VB - Select List to Html.Dropdownlist
问题描述
似乎我找到的大多数示例都是c#,所以在某些情况下,我会挠头...总而言之,我只是想将项目的selectList输出到一个下拉列表中在我看来:
Seems most of the examples I find are c#, so in some cases I'm left scratching my head... to make a long story short, I'm simply trying to output the selectList of items to a drop-down within my view:
我的ViewModel:
My ViewModel:
Imports System.Web
Imports Whitebox.UI
Namespace ViewModels
Public Class TFS_VModel
Public Property AccType() As IEnumerable(Of LibAcctType)
Get
Return m_types
End Get
Set(ByVal value As IEnumerable(Of LibAcctType))
m_types = value
End Set
End Property
Private m_types As IEnumerable(Of LibAcctType)
End Class
End Namespace
我的控制器:
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web.Mvc
Imports Whitebox.UI
Imports Whitebox.UI.ViewModels
<HandleError()> _
Public Class TFSController
Inherits Controller
Dim _DB As New BlackBoxNormalizedEntities()
Function TFSMain() As ActionResult
Dim AccTypeList = (From m In _DB.LibAcctType Select m).ToList()
Dim viewModel As New TFS_VModel()
viewModel.AccType = AccTypeList
Return View(viewModel)
End Function
End Class
我现在要做的只是在我的视图中将我的"SelectList"输出到HTML.DROPDOWNLIST()中.任何帮助将不胜感激.逐步执行时,我的列表项会显示在"Return view(viewmodel)"手表中,但我仍然无法执行输出.
All I'm trying to do now is simply output my "SelectList" within a HTML.DROPDOWNLIST() in my view... any help would be greatly appreciate. When doing a step through, my list items are showing within my "Return view(viewmodel)" watch, but I'm stuck with performing the output.
推荐答案
您将需要在视图模型中添加一个包含所选帐户类型的属性:
You will need to add a property in your view model that will hold the selected account type:
Public Class TFS_VModel
Public Property AccType() As IEnumerable(Of LibAcctType)
Get
Return m_types
End Get
Set(ByVal value As IEnumerable(Of LibAcctType))
m_types = value
End Set
End Property
Private m_selectedAccType As String
Public Property SelectedAccType() As String
Get
Return m_selectedAccType
End Get
Set(ByVal value As String)
m_selectedAccType = value
End Set
End Property
Private m_types As IEnumerable(Of LibAcctType)
End Class
然后在您看来:
<%= Html.DropDownListFor(Function(x) x.SelectedAccType, New SelectList(Model.AccType, "Id", "Text", Model.SelectedAccType)) %>
下拉列表由 LibAcctType
的 AccType
集合构造而成,并且 Id
和 Text
应该是属性 LibAcctType
的形式.
The drop down list is constructed from the AccType
collection of LibAcctType
and Id
and Text
should be properties of this LibAcctType
.
这篇关于VB中的MVC.NET-选择要Html.Dropdownlist的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!