This is my Query =>
var department = dataContext.Query<Department>("SELECT Id FROM tblDepartment");
I want to display the values in variable Department in ViewBag or Anywhere.How can I do that?
This is my Query =>
var department = dataContext.Query<Department>("SELECT Id FROM tblDepartment");
I want to display the values in variable Department in ViewBag or Anywhere.How can I do that?
You can use linq to Entities without executing raw queries as:
var department = dataContext.Department.Select(x=>x.Id).ToList();
If you are stubborn to use raw query, you can use as teo van kot has suggested above:
var department = dataContext.Query<Department>("SELECT Id FROM tblDepartment").ToList();
You can assign the list to ViewBag
in controller as:
ViewBag.DepartmentIDs = department;
You can display the values in View as:
@{
foreach(var item in ViewBag.DepartmentIDs)
{
<span>@item <br/></span>
}
}
and then work with list