I\'m iterating a List in a razor foreach loop in my view which renders a partial. In the partial I\'m rendering a single record for which I want to hav
In case you want to count the references from your model( ie: Client has Address as reference so you wanna count how many address would exists for a client) in a foreach loop at your view such as:
@foreach (var item in Model)
{
@Html.DisplayFor(modelItem => item.DtCadastro)
@Html.DisplayFor(modelItem => item.DsLembrete)
@Html.DisplayFor(modelItem => item.DtLembrete)
@{
var contador = item.LembreteEnvolvido.Where(w => w.IdLembrete == item.IdLembrete).Count();
}
}
do as coded:
@{ var contador = item.LembreteEnvolvido.Where(w => w.IdLembrete == item.IdLembrete).Count();}
and use it like this:
ps: don't forget to add INCLUDE to that reference at you DbContext inside, for example, your Index action controller, in case this is an IEnumerable model.