I have a database with 2 tables (clients and cars). The table cars have a column named client_id. In my Razor Pages project I have the models created for the 2 tables, but I need do a INNER JOIN to return the result to view side and do a foreach loop. So until now I used the IList and do this in .cshtml:
@foreach (var item in Model.clients)
{
<p>@Html.DisplayFor(x=> item.name)</p>
<p>@Html.DisplayFor(x=> item.mail)</p>
}
And in code cshtm.cs
public IList<establishments> establishments;
IQueryable<establishments> establishments_filter;
establishments_filter = (from x in db.establishments where x.category == category select x);
establishments = establishments_filter.ToList();
Now the problem is that I cant do the same with a Inner Join or I don´t know how (most probably). I see in others posts that I can use a variable to receive the values like this:
var filter = (from x in db.cars join y in db.clients on x.id_client == y.id select new {
mark = x.mark,
model = x.model,
name = y.name,
mail = y.name
}.ToList();
But now, my real question... How I can do a foreach if the var filter is not acessible in cshtml?
Thanks