ASP.NET MVC application, so I started a new program that contains the count of items in the database based on the group, and I have used the ASP.NET MVC to do it.
My model class have the following details
public class Project
{
public int ProjectID { get; set; }
[Required]
public string ProjectName { get; set; }
[Required]
public string ProjectDescription { get; set; }
[Required]
public string ProjectScope { get; set; }
[Required]
public string ProjectFamily { get; set; }
[Required]
public string ProjectBucket { get; set; }
[Required]
public string ProjectType { get; set; }
[Required]
public string ProjectStatus { get; set; }
public string Categoryname { get; set; }
public int Count { get; set; }
}
and Controller has the following code
public IActionResult Count()
{
//Your EntityModel or business logic for fetching the records.
ProjectDataAcces entities = new ProjectDataAcces();
var images = entities.GetAllProject().GroupBy(n => n.ProjectFamily)
.Select(g => new { ProjectFamily = g.Key, Count = g.Count() }).ToList();
List<Project> imagesList = new List<Project>();
for (int i = 0; i < images.ToList().Count; i++)
{
imagesList.Add(new Project { ProjectFamily = images[i].ProjectFamily, Count = images[i].Count });
}
return View(imagesList);
}
by using this I have to get the count in my view page. How can I do this?
and my view page is
<div class="col-6 col-md-4 col-xl-2">
<div class="card ca-bg">
<div class="card-body ribbon bucket-cursor">
<div class="ribbon-box orange" id="count1"></div>
<div class="my_sort_cut text-muted1">
<i class="icon-list"></i>
<span>800xA Incl Safety</span>
</div>
</div>
</div>
</div>
<div class="col-6 col-md-4 col-xl-2">
<div class="card ca-bg">
<div class="card-body ribbon bucket-cursor">
<div class="ribbon-box orange" id="count2"></div>
<div class="my_sort_cut text-muted1">
<i class="icon-like"></i>
<span>Aprol</span>
</div>
</div>
</div>
</div>
<div class="col-6 col-md-4 col-xl-2">
<div class="card ca-bg">
<div class="card-body ribbon bucket-cursor">
<div class="ribbon-box orange" id="count3"></div>
<div class="my_sort_cut text-muted1 ">
<i class="icon-credit-card"></i>
<span>Compact Products</span>
</div>
</div>
</div>
</div>
<div class="col-6 col-md-4 col-xl-2">
<div class="card ca-bg">
<div class="card-body ribbon bucket-cursor">
<div class="ribbon-box orange" id="count4"></div>
<div class="my_sort_cut text-muted1 ">
<i class="icon-doc"></i>
<span>Freelance</span>
</div>
</div>
</div>
</div>
In this I have to show the count in id="count1" id="count2" place....How to view the count by group by?