C# 如何将LINQ查询返回到视图模型
因此,我的控制器中有以下操作:C# 如何将LINQ查询返回到视图模型,c#,asp.net-mvc,linq,C#,Asp.net Mvc,Linq,因此,我的控制器中有以下操作: public ActionResult List() { ViewBag.Title = "View Current Stores"; var curStores = (from store in stores.Stores where store.CompanyID == curCompany.ID select store).ToList();
public ActionResult List() {
ViewBag.Title = "View Current Stores";
var curStores =
(from store in stores.Stores
where store.CompanyID == curCompany.ID
select store).ToList();
return View(curStores);
}
假设它获取一个存储列表,并将其呈现为视图中的表。但是,LINQ语句引发以下错误:
Non-static method requires a target.
我应该怎么做?尝试使用
stores.stores.Where(o=>o.CompanyID==curCompany.ID).ToList()
;但请确保操作中使用但未定义的其他变量(即curCompany和stores)是有效的。这可能是因为curCompany
控制器构造函数中是否填充了null curCompany?你能分享那个密码吗?是的,公司是空的。我是MVC新手,所以我还没有真正弄清楚如何在这种环境下加载数据。