0

如何使用列表中的数据查询视图?

例如:下面,我有变量“数据”,我将所有 id 从视图存储到列表中。我想查询第二个视图“vwStatus”,以便它返回列表中显示状态的所有行(数据)

就像是:

public ActionResult Index(string id)
{
    var data = (from p in db.vwdb.Where(p => p.ID == id)
                 group p by p.status into g select g.Key).ToList();

    ViewData.Model = db.vwStatus.Where(p => p.Status == data);           

    return View();
}

希望我说清楚了。

4

1 回答 1

1

你可以这样做:

var data = (from p in db.vwdb.Where(p => p.ID == id)
                 group p by p.status into g select g.Key).ToList();

//Here you'll get the data you want from the database:
ViewData.Model = db.vwStatus.Where(vw => data.Contains(vw.Id));

return View();

这应该可以正常工作。

问候。

于 2012-10-30T18:41:41.427 回答