html - 如何使用 Visual Basic.NET 和 ASP.NET MVC 创建下拉列表并检索所选项目的值?
问题描述
我想使用 VB.NET HTML MVC 下拉列表创建并将其选定的项目检索到控制器中的另一个方法中。
下面是检索下拉列表值的方法的代码:
Function InputSetup() As ActionResult
Dim inputStreamsDataSetup_Tbl = db.InputStreamsDataSetup_Tbl.Include(Function(i) i.Streams_Tbl).Include(Function(i) i.InputStreamsVariable_Tbl)
ViewBag.SubFlowsheet = New SelectList(GetSubflow(), "SubFlowsheet", "SubFlowsheet")
Return View(inputStreamsDataSetup_Tbl.ToList())
End Function
这是显示下拉列表的 vbhtml 标记
@Html.DropDownList("SubFlowsheet", Nothing, "--Select SubFlowsheet--", New With {Key .onchange = "location.href=' @Url.Action('BindStreams', 'InputStreamsDataSetup_Tbl')'"})
我想BindStreams
在所选更改上调用函数
Function BindStreams(ByVal Flowsheet As String) As JsonResult
Using con As New SqlConnection(Str)
Using cmd As New SqlCommand("select * from Streams_Tbl where SubFlowsheet='" + Flowsheet + "'", con)
Dim Streams As New List(Of Streams_Tbl)
cmd.CommandType = CommandType.Text
con.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
Streams.Add(New Streams_Tbl With {
.Stream_Name = sdr("Stream_Name").ToString(),
.Stream_ID = sdr("Stream_ID").ToString()
})
End While
End Using
con.Close()
Return Json(Streams, JsonRequestBehavior.AllowGet)
End Using
End Using
End Function
提前致谢
解决方案
推荐阅读
- python - 为什么我在终端上安装的软件包不能在 Spyder 上运行
- python - 如何在空的高山容器上安装 python
- python - Pyqt5 或 dash with plotly 用于交互式仪表板
- node.js - 如何使用工作服修复“405 Not Allowed”错误
- python - 为什么我的 Array Rotation 解决方案似乎正确,但在 Leetcode 上却显示错误?
- python - 使用for循环python在两个列表中查找常见项目 - 降低时间复杂度
- python - 导出和加载嵌套的 Pydantic 模型
- javascript - REACT JS - 如何在地图内进行求和?
- mysql - 使用可变数量的参数在 Hibernate 方言中注册 MySQL 函数
- qt - Enable 属性不适用于 tableview 和 delegateChooser QML