Ale*_*eta 1 c# linq drop-down-menu
我正在使用LINQ填充"类别"下拉列表.(Northwind数据库)
var Category = (from cat in _db.Categories.ToList()
select new SelectListItem
{
Text = cat.CategoryName,
Value = cat.CategoryID.ToString()
}).ToList();
Run Code Online (Sandbox Code Playgroud)
我希望在此列表的开头添加一个额外的值作为过滤器重置,类似于"全部",所以我希望下拉列表类似于:
var Category = new[]{ new SelectListItem(){ Text = "All" } }.Concat(
from cat in _db.Categories.ToList()
select new SelectListItem
{
Text = cat.CategoryName,
Value = cat.CategoryID.ToString()
}).ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4089 次 |
| 最近记录: |