这是我的Query =>
var department = dataContext.Query<Department>("SELECT Id FROM tblDepartment");
我想在ViewBag或Anywhere中的变量Department中显示值。我可以这样做吗?
答案 0 :(得分:1)
您可以使用 linq to Entities 而不执行原始查询:
var department = dataContext.Department.Select(x=>x.Id).ToList();
如果你顽固地使用原始查询,你可以使用如上所述的teo van kot:
var department = dataContext.Query<Department>("SELECT Id FROM tblDepartment").ToList();
您可以将列表分配给控制器中的ViewBag
:
ViewBag.DepartmentIDs = department;
您可以在View中显示值:
@{
foreach(var item in ViewBag.DepartmentIDs)
{
<span>@item <br/></span>
}
}
答案 1 :(得分:1)
var department = dataContext.Query<Department>("SELECT Id FROM tblDepartment").ToList()
然后使用列表