you lack a ViewModel
your anonymous
select new{
CategoryId=cat.Id,
Title = en.Title,
Username =en.Username,
Password =en.Password,
Url = en.Url,
Description = en.Description,
Category=cat.Name
};
should be an entity
for example a class called EntriesWithCateogories
public class EntriesWithCateogories
{
public int CateogiryId {get;set;}
public string Category {get;set;}
public string Title {get;set;}
...
}
then your query becomes
var query = from cat in _db.Categories
join en in _db.Entries on cat.Id equals en.CategoryId
select new EntriesWithCateogories{
CategoryId=cat.Id,
Title = en.Title,
Username =en.Username,
Password =en.Password,
Url = en.Url,
Description = en.Description,
Category=cat.Name
};
return View(query.ToList());
and your View NEED at the top
@model IEnumerable<EntriesWithCategories>
on the other hand you can create a real ViewModel that contains the list
ex :
public class EntriesCategoryViewModel {
public string PageTitle {get;set;}
public List<EntriesWithCategories> List {get;set;}
}
and your controller code becomes
var model = new EntriesCategoryViewModel();
model.Title = " my page title";
model.List = query.ToList();
return View(model);
and the view
@model EntriesCategoryViewModel
@foreach (var item in Model.List)
{
<div>@item.Category</div>
}