将内部联接Linq查询放置到视图模型中

本文关键字:视图 模型 查询 内部 Linq | 更新日期: 2023-09-27 18:19:47

Viewmodel:

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,
                     });
}

如何在MVC中将c.location输出到剃刀视图中?我遇到的最常见的错误是无法进行从IQueryableSystem.Generic.Collection的转换。错误在代码中说明。

将内部联接Linq查询放置到视图模型中

.ToArray()替换为.ToList().AsQueryable(),这能奏效吗?