简体   繁体   中英

Placing Inner Join Linq Query Into View Model

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;

Controller:

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

How do I out c.location into razor view within MVC? The most common error I get is can't do conversion from IQueryable to System.Generic.Collection . The error is stated within the code.

.ToList().AsQueryable()替换.ToArray() ,这能解决问题吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM