ASP.net MVC3 entities, don't know how to count

Posted by Spedax on Stack Overflow See other posts from Stack Overflow or by Spedax
Published on 2012-03-24T11:24:04Z Indexed on 2012/03/24 11:29 UTC
Read the original article Hit count: 235

I have 2 tables, 1 with countries, 1 with states. The states table has a column with Population.

I'm using entities and I have created a List of states for the countries

public class TblCountries
{
//Entities for my table country
...
public List<tblStates> States { get; set; }
}

So now I can for example List all the states that belong to a country.

Now what I want to do is count the population, so I can show the population that of an entire country.

I tried using in my view

@foreach (var item in Model.Countries) {
 @Html.DisplayFor(modelItem => item.States.Count<population>)
}

But this doesn't work, anyone know how to do this?

Thanks in advanced!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc