我有这个下拉列表而没有显示数据,我有一些错误?
var City = from s in db.City_Office
join c in db.City on s.IdCityOffice equals c.IdCity
select c;
ViewBag.IdCityoffice = new SelectList(City, "IdCity", "NameCity");
答案 0 :(得分:0)
首先,您的查询可能不返回任何数据。其次,您希望立即强制执行查询。
简单地“选择”不会执行它。你需要使用它。调用ToList()将强制执行(如果期望一个,则调用Single())
var City = (from s in db.City_Office
join c in db.City on s.IdCityOffice equals c.IdCity
select c).ToList();