Here is my scenario: We would like to have a page listing donors, depending on the user viewing the page we would like to group by the donor's giving level, or just their sort name. The twist that is throwing me is that we would like to group the Anonomous Donors and give a count based on the grouping.
In my controller I have
[HttpGet]
public ActionResult Society(string id)
{
var society = _db.ONLINEDR_DONOR_LIST
.Include("ONLINEDR_DONORS")
.Single(s => s.DONOR_LIST_ID == id);
var donors = _db.ONLINEDR_DONORS
.Where(d => d.DONOR_LIST_ID == id)
.OrderBy(d => d.SUBGROUP_SORT)
.ThenBy(d => d.SORT_NAME)
.ToList();
if (User.Identity.Name == "public")
{
//First off, check to make sure the list is viewable.
if (society.PUBLIC_IND == "N")
RedirectToAction("Index", "Home");
donors = _db.ONLINEDR_DONORS
.Where(d => d.DONOR_LIST_ID == id)
.OrderBy(d => d.SORT_NAME)
.ToList();
}
var viewModel = new SocietyDetailViewModel()
{
Society = society,
Donors = donors
};
return View(viewModel);
}
I would like to have something like
donors = _db.ONLINEDR_DONORS
.Where(d => d.DONOR_LIST_ID == id)
.GroupBy(d => d.SORT_NAME)
.ToList();
Which I can pass to my view, and then somehow show in the view
<% if (Model.donor.GroupedByItemCount > 1) { %>
<%: Model.donor.GroupedByItemCount %>
<% } %
(I am still new to asp.net MVC and LINQ so any helpful references to explain what I am doing wrong would be appreciated as well).
Thanks so much.