Hi i want to count the total number of rows in my view . I will explain my issue clearly..
My output
1) i want to count the total no of rows in the view and want to display that count in the same view of right top corner
2) I have three Customer Type New customer, Potential Customer, Existing Customer. i want to count the each type and want to display it in right top corner of the view.
I gave as like this @Model.Sum(i => i.CustomerName) but it showing error and i donno where i have to declare this line and how to calculate the Types and show in the view. please any one give
suggestion or solution for my problem.
My View
@model IEnumerable
@{
ViewBag.Title = "customerid";
}
CustomerType
Customer
| Customer Name | Customer Type |
|---|---|
@i.CustomerName | @i.CustomerType |
| Customer Name |
public class CustomerTypeViewModel
{
public System.Guid CustomerID { get; set; }
public string CustomerName { get; set; }
public DateTime CreatedDate { get; set; }
public string SalesCount { get; set; }
public string CustomerType { get; set; }
}
My controller
public ActionResult customerid()
{
List n = (from c in db.Customers where c.IsDeleted == false select c).ToList();
var customertype = string.Empty;
List obj = new List();
for (var i = 0; i < n.Count; i++)
{
var objCustomerName = n[i].DisplayName;
var objCustomerID = n[i].CustomerID;
var objCusCreatedDate = n[i].CreatedDate;
var objNextDate = objCusCreatedDate.GetValueOrDefault().AddDays(120);
var salescount = (from sc in db.SalesOrders where sc.CustomerID == objCustomerID && sc.CreatedDate >= objCusCreatedDate && sc.CreatedDate <= objNextDate select sc.SalesOrderID).Count();
if (salescount <= 3 && salescount > 0)
{
customertype = "potential Customer";
}
else if (salescount >= 3)
{
customertype = "Existing Customer";
}
else
{
customertype = "New Customer";
}
obj.Add(new CustomerTypeViewModel()
{
CustomerName = objCustomerName,
CustomerType = customertype,
SalesCount = salescount.ToString()
});
}
return View(obj);
}

Saillesh PawarRank #537 · 4.5K reputationPosted Mar 28, 2016, 9:16 PM EDT
Sneha KRank #2,496 · 563 reputationPosted Mar 28, 2016, 9:20 PM EDT
Saillesh PawarRank #537 · 4.5K reputationPosted Mar 28, 2016, 9:34 PM EDT
Sneha KRank #2,496 · 563 reputationPosted Mar 28, 2016, 9:36 PM EDT
Saillesh PawarRank #537 · 4.5K reputationPosted Mar 28, 2016, 9:40 PM EDT
Sneha KRank #2,496 · 563 reputationPosted Mar 28, 2016, 9:47 PM EDT
Saillesh PawarRank #537 · 4.5K reputationPosted Mar 28, 2016, 9:48 PM EDT
Sneha KRank #2,496 · 563 reputationPosted Mar 28, 2016, 10:05 PM EDT
Saillesh PawarRank #537 · 4.5K reputationPosted Mar 28, 2016, 10:11 PM EDT
Sneha KRank #2,496 · 563 reputationPosted Mar 28, 2016, 10:13 PM EDT
Shuvojit HalderRank #2,827 · 503 reputationPosted Mar 28, 2016, 10:25 PM EDT