在ASP.NET中使用Lambda进行主/明细下拉过滤 [英] Master/Detail dropdown filtering using Lambda in ASP.NET
问题描述
我想根据上一个字段中选择的内容填充一个下拉列表.
I'd like to populate a dropdown list based on the selection chosen in the previous field.
目前,我的 ViewModel
中有2个列表,如下所示:
Currently I have 2 Lists from my ViewModel
like so:
Manufacturers = context.ManufacturersTable.OrderBy(x => x.ManufacturerName).ToList(),
Models = context.ModelsTable.OrderBy(x => x.ModelName).ToList(),
两个列表都使用具有自己数据模型的SQL表填充.
Both lists are populated using a SQL Table with their own data model.
在 Models
表中,我有一个 ManufacturerID
列,该列与 Manufacturers
中的 ManufacturerID
匹配.>表格.
In the Models
table, I have a column for ManufacturerID
which matches that of the ManufacturerID
in the Manufacturers
table.
我想根据对 Manufacturers
列表的选择来填充 Models
列表,以便仅显示与所选制造商关联的模型.
I'd like to populate the Models
list based on the selection of the Manufacturers
list so that only models associated with the selected manufacturer are displayed.
我该如何使用 Lambda
?
我一直在玩哪里"和选择",但还没完全能够到达那里.
I've been playing with Where and Select but haven't quite been able to get there.
这是桌子
MANUFACTURER | MANUFACTURER_ID
Manufacturer 1 GUID1
Manufacturer 2 GUID2
MODEL | MODEL_ID | MANUFACTURER_ID
Model 1 | GUID1 | GUID1
Model 2 | GUID2 | GUID2
Model 3 | GUID3 | GUID1
Model 4 | GUID4 | GUID1
推荐答案
context.ModelsTable.Where(x => x.ManufacturerId == value).OrderBy(x => x.ModelName).ToList()
这行不通吗?将ManufactureId作为 value
传递.此处
关键字过滤数据,但返回表中的所有列.使用 Select
,您可以选择要返回的列.您可以一起使用这些关键字.
This doesn't work? Pass ManufactureId as value
.
Where
keyword filter data but returns all columns from the table. With Select
you can select which columns you want to return. You can use these keywords together.
这篇关于在ASP.NET中使用Lambda进行主/明细下拉过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!