[英]Placing Inner Join Linq Query Into View Model
視圖模型:
public IEnumerable<Telephone_Search.Models.tbl_users> users;
public IEnumerable<Telephone__Search.Models.tbl_pics> images;
public IEnumerable<Telephone__Search.Models.tbl_locations> branches;
控制器:
public ActionResult Index()
{
var users = from a in db.tbl_users
where a.userid == 6
select a;
var branchjoin = (from e in db.users
join c in db.tbl_locations on e.address equals c.location
where e.userid == 6 && e.emp_address == c.location
select c).ToArray();
return this.View(new ViewModel
{
branches = branchjoin // Error here
users = users,
});
}
我如何將c.location
放入MVC的razor視圖中? 我遇到的最常見錯誤是無法從IQueryable
轉換為System.Generic.Collection
。 錯誤在代碼中說明。
用.ToList().AsQueryable()
替換.ToArray()
,這能解決問題嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.