I'm trying to get a list of all area in my database:
public ActionResult Index()
{
var carreras = repo.FindAllCarreras().ToList();
AreaRepository area = new AreaRepository();
ViewData["Areas"] = area.FindAllAreas(); //Return IQueryable<>
return View("Index", carreras);
}
And in the View:
<% foreach (var area in ViewData["Areas"])
{ %>
<p><%: area %></p>
<% } %>
I get an error:
foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
I think the best route would be modifying the query in the CarreraController and creating a linq query that returns all the names and saving it to a simple List.
How can I achieve this?
ViewData["Areas"] = area.FindAllAreas().Select(????