我有这个 ViewModel:
public DashboardViewModel(Dashboard dashboard)
{
HardwareType hwt = new HardwareType { HType = "PC" };
IQueryable<Hardware> Pcs = db.Hardware.Where(h => h.HardwareType.Contains(hwt));
}
我想将 Pcs 变量传递给我的视图,以便可以遍历它。这是我的控制器:
public ActionResult Index()
{
ViewBag.Title = "ULS Computer Inventory Tracker";
Dashboard dashboard = new Dashboard();
var dashbaordViewModel = new DashboardViewModel(dashboard);
return View(dashboardViewModel);
}
而我的观点:
@{
@model CIT.ViewModels.DashboardViewModel
}
...
@foreach (var item in Pcs) {
<li><a href="#" class="btn"><i class="icon-hdd"></i> @item.HardwareType</a></li>
}
但是我得到一个Pcs
在当前上下文中不存在的错误。我在这里做错了什么?