title: ASP.NET MVC - How Can I Calculate the Total Value With Sum and Count in View
body: <p>I am new in ASP.NET MVC. There are 2 tables in my database named "tbl_Project" and "tbl_Note". Each project can have one or more notes, so I keep/save the "ProjectID" variable in the "tbl_Note".</p>
  
  <p>What I want to do: On the page where the project list is located, I want to show the total number of notes for each project. I tried a few things but I've fail.</p>
  
  <p>This is my projects list page:</p>
  
  <pre><code>@if(Model.Any())
  {
      &lt;table class="table table-striped table-hover table-bordered" id="sample_editable_1"&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;Total Note&lt;/th&gt;
                  &lt;th&gt;Project Name&lt;/th&gt;
                  &lt;th&gt;Contract Start Date&lt;/th&gt;
                  &lt;th&gt;Contract End Date&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          @foreach (var item in Model)
          {
              &lt;tbody&gt;
                  &lt;tr&gt;
                      &lt;td&gt;
                          &lt;!-- Total number of notes will come here --&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                          &lt;p&gt;&lt;a href="@Url.Action("Detail", "Project", new { ID = item.ID })" data-tooltip="@(item.Information != null? item.Information:"")"&gt;@item.ProjectName&lt;/a&gt;&lt;/p&gt;
                      &lt;/td&gt;
                      &lt;td&gt;
                         @item.ContractStartDate.Value.ToString("dd.MM.yyyy");
                      &lt;/td&gt;
                      &lt;td&gt;
                          @item.ContractEndDate.Value.ToString("dd.MM.yyyy");
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          }
      &lt;/table&gt;
  }
  else
  {
      &lt;p&gt;Project is not available!&lt;/p&gt;
  }
  </code></pre>
  
  <p>I've try something like this but it's not working:</p>
  
  <pre><code>@if(item.tbl_Note != null)
  {
      if(item.tbl_Note.ProjectID == Model.ProjectID) 
      {
          @Model.Sum(b =&gt; b.tbl_Note.ProjectID.Count)
      }
  }
  </code></pre>
  
  <p>This line gives an error: item.tbl_Note.ProjectID and the error is: 'ICollection' does not contain a definition for 'ProjectID and no extension method 'ProjectID' accepting a first argument of type 'ICollection' could be found.</p>
  
  <p>How can I calculate the total number of notes? And if there is any other code block you want to insert, please tell me.</p>